1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.systemui.recents.model;
18 
19 import com.android.systemui.shared.recents.model.Task;
20 import java.util.concurrent.ConcurrentLinkedQueue;
21 
22 /**
23  * A Task load queue
24  */
25 class TaskResourceLoadQueue {
26 
27     private final ConcurrentLinkedQueue<Task> mQueue = new ConcurrentLinkedQueue<>();
28 
29     /** Adds a new task to the load queue */
addTask(Task t)30     void addTask(Task t) {
31         if (!mQueue.contains(t)) {
32             mQueue.add(t);
33         }
34         synchronized(this) {
35             notifyAll();
36         }
37     }
38 
39     /**
40      * Retrieves the next task from the load queue, as well as whether we want that task to be
41      * force reloaded.
42      */
nextTask()43     Task nextTask() {
44         return mQueue.poll();
45     }
46 
47     /** Removes a task from the load queue */
removeTask(Task t)48     void removeTask(Task t) {
49         mQueue.remove(t);
50     }
51 
52     /** Clears all the tasks from the load queue */
clearTasks()53     void clearTasks() {
54         mQueue.clear();
55     }
56 
57     /** Returns whether the load queue is empty */
isEmpty()58     boolean isEmpty() {
59         return mQueue.isEmpty();
60     }
61 }
62