scoop:scoop.concurrent:0.1.0
src/coroutine_worker_context.scoop
Selected production source · src/coroutine_worker_context.scoop
1
package scoop.concurrent3
@ThreadLocal4
private var physicalCoroutinePool: Long = 0L6
@ThreadLocal7
private var physicalCoroutineWorker: Int = -19
// Scalar TLS identifies the actual producer of a local queue without placing10
// moving managed references in native thread-local storage.11
internal 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
@Unsafe18
{19
physicalCoroutinePool = pool20
physicalCoroutineWorker = worker21
}22
}24
internal fun leave() {25
@Unsafe26
{27
physicalCoroutineWorker = -128
physicalCoroutinePool = 0L29
}30
}32
internal fun current(pool: Long): Int {33
@Unsafe34
{35
if (physicalCoroutinePool == pool)36
return physicalCoroutineWorker37
return -138
}39
}40
}