Scoop API

scoop:scoop.concurrent:0.1.0

src/coroutine_worker_context.scoop

Selected production source · src/coroutine_worker_context.scoop

1package scoop.concurrent
3@ThreadLocal
4private var physicalCoroutinePool: Long = 0L
6@ThreadLocal
7private var physicalCoroutineWorker: Int = -1
9// Scalar TLS identifies the actual producer of a local queue without placing
10// moving managed references in native thread-local storage.
11internal object CoroutineWorkerContext {
12 private val identities = AtomicLong(1L)
14 internal fun nextIdentity(): Long = identities.fetchAdd(1L)
16 internal fun enter(pool: Long, worker: Int) {
17 @Unsafe
18 {
19 physicalCoroutinePool = pool
20 physicalCoroutineWorker = worker
21 }
22 }
24 internal fun leave() {
25 @Unsafe
26 {
27 physicalCoroutineWorker = -1
28 physicalCoroutinePool = 0L
29 }
30 }
32 internal fun current(pool: Long): Int {
33 @Unsafe
34 {
35 if (physicalCoroutinePool == pool)
36 return physicalCoroutineWorker
37 return -1
38 }
39 }