Scoop API

scoop:scoop.concurrent:0.1.0

src/multi_thread_ticket.scoop

Selected production source · src/multi_thread_ticket.scoop

1package scoop.concurrent
3internal class MultiThreadTicket(
4 internal val owner: MultiThreadExecutor,
5 worker: Int
6): ExecutorTask {
7 internal val affinity = AtomicInt(worker)
8 private val admitted = AtomicBoolean(true)
9 internal val active: Boolean get() = admitted.load()
11 // The owner serializes registration and retirement with its lifecycle mutex.
12 internal fun retire() {
13 admitted.store(false)
14 }
16 public override val executor: CoroutineExecutor get() = owner
18 public override fun dispatch(work: CoroutineWork) {
19 owner.dispatch(this, work)
20 }
22 public override fun dispatchResume(work: CoroutineWork) {
23 owner.dispatch(this, work, true)
24 }
26 public override fun dispatchBlocking(work: BlockingWork) {
27 owner.dispatchBlocking(this, work)
28 }
30 public override fun complete() {
31 owner.complete(this)
32 }