1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798open!Baseopen!ImportmodulerecJob:sig@@portabletype'at=Parallel.t@local->'aResult.Capsule.t@localuniqueend=JobandThunk:sig@@portabletype'at=Parallel.t@local->'aend=ThunkandOps:sig@@portable(* Subtasks must not [Await] or [Yield]; [Parallel.t] does not provide the capability. *)type'at=|Promise:'aPromise.t->('aResult.Capsule.t*tokens:int)t(** When filled, pushes the continuation to the local queue. Used by [Promise.t]. *)|Await:Trigger.t->unitt(** When signaled, pushes the continuation to the global queue. Used by [Await.t]. *)|Yield:unitt(** Immediately pushes the continuation to the global queue. Used by [Yield.t]. *)end=OpsandWait:(Handled_effect.Swithtype('a,_)ops:='aOps.t)=Handled_effect.Make(Ops)andPromise:sig@@portabletype'acontinuation=('a,(unit,unit)Wait.Contended.Result.t,unit)Handled_effect.Continuation.ttype'astate=|Start|Claimed|Blocking:{key:'kCapsule.Key.t@@many;cont:(('aResult.Capsule.t*tokens:int)continuation,'k)Capsule.Data.t@@many}->'astate|Readyof{result:'aResult.Capsule.t@@contendedmanyportable;tokens:int}type'at='astateUnique.Atomic.tend=PromiseandRunqueue:sig@@portabletype_node=|Cons1:{mutablepromise:'aPromise.tor_null;job:'aJob.t@@globalportable;mutabledown:nodes}->('a*unit)node|ConsN:{mutablepromise:'aPromise.tor_null;job:'aJob.t@@globalportable;more:('b*'l)node}->('a*('b*'l))nodeandnodes=Q:_nodeStack_pointer.t->nodes[@@unboxed]typet={mutabletokens:int;mutablehead:nodes;mutablecursor:nodes}end=RunqueueandScheduler:sig@@portabletypet:(value&value&value)modcontendedportable=#{task:(unit->unit)@onceportable->unit@@portable(** Pushes a concurrent task (which may await/yield) to the global queue. *);subtask:(unit->unit)@onceportable->unit@@portable(** Pushes a parallel subtask (which can only sync) to the local queue. *);try_wake:n:int->unit@@portable(** Signals up to [n] workers that are currently asleep. *)}end=SchedulerandParallel:sig@@portabletypet=|Sequential|Parallel:{password:'kCapsule.Password.t@@many;queue:(Runqueue.t,'k)Capsule.Data.t;handler:Wait.tHandled_effect.Handler.t@@contendedportable;scheduler:Scheduler.t@@globalmany}->tend=Parallel