• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.shared.recents.model;
18 
19 import java.util.concurrent.ConcurrentLinkedQueue;
20 
21 /**
22  * A Task load queue
23  */
24 class TaskResourceLoadQueue {
25 
26     private final ConcurrentLinkedQueue<Task> mQueue = new ConcurrentLinkedQueue<>();
27 
28     /** Adds a new task to the load queue */
addTask(Task t)29     void addTask(Task t) {
30         if (!mQueue.contains(t)) {
31             mQueue.add(t);
32         }
33         synchronized(this) {
34             notifyAll();
35         }
36     }
37 
38     /**
39      * Retrieves the next task from the load queue, as well as whether we want that task to be
40      * force reloaded.
41      */
nextTask()42     Task nextTask() {
43         return mQueue.poll();
44     }
45 
46     /** Removes a task from the load queue */
removeTask(Task t)47     void removeTask(Task t) {
48         mQueue.remove(t);
49     }
50 
51     /** Clears all the tasks from the load queue */
clearTasks()52     void clearTasks() {
53         mQueue.clear();
54     }
55 
56     /** Returns whether the load queue is empty */
isEmpty()57     boolean isEmpty() {
58         return mQueue.isEmpty();
59     }
60 }
61