-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAccessibilityCommandQueue.kt
More file actions
39 lines (31 loc) · 902 Bytes
/
AccessibilityCommandQueue.kt
File metadata and controls
39 lines (31 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.google.ai.sample
import com.google.ai.sample.util.Command
import java.util.LinkedList
import java.util.concurrent.atomic.AtomicBoolean
internal class AccessibilityCommandQueue {
private val queue = LinkedList<Command>()
private val processing = AtomicBoolean(false)
@Synchronized
fun clearAndUnlock() {
queue.clear()
processing.set(false)
}
@Synchronized
fun enqueue(command: Command): Int {
queue.add(command)
return queue.size
}
@Synchronized
fun peek(): Command? = queue.peek()
@Synchronized
fun poll(): Command? = queue.poll()
@Synchronized
fun size(): Int = queue.size
@Synchronized
fun isEmpty(): Boolean = queue.isEmpty()
fun tryAcquireProcessing(): Boolean = processing.compareAndSet(false, true)
fun releaseProcessing() = processing.set(false)
}
/*
test
*/