1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586includeDynamic_intfmoduleFiber_dynamic:Dynamic=struct(* Stacks are represented as tagged pointers, so do not keep the fiber alive. We must
not enter the GC between the creation and use of a [stack]. *)typelast_fiber:immediatetype(-'a,+'b)cont(** Interface to Dynamic implemented in the runtime. The runtime implementation of
[Dynamic.set_root] sets the per-domain root value, but we want the root value to be
global, so we wrap the runtime version in our own version with a global atomic for
the root value. *)moduleRuntime_dynamic=structtype('a:value_or_null)t:valuemodcontendedportableexternalreperform:'aStdlib.Effect.t->('a,'b)cont@unique->last_fiber->'b@unique@@portable="%reperform"externalwith_stack_dyn:'a'b'c('d:value_or_nullmodcontended)'e.('a->'b)->(exn->'b)->('cEffect.t->('c,'b)cont@unique->last_fiber->'b@unique)->'dt->'d@portable->('e@onceunique->'a)@once->'e->'b@@portable="%with_stack_bind""%with_stack_bind"externalmake:('a:value_or_nullmodcontended).'a@portable->'at@@portable="basement_dynamic_make"externalget:('a:value_or_nullmodcontended).'at->'a@portable@@portable="basement_dynamic_get"letwith_temporarilydv~f=leteffceffklast_fiber=reperformeffklast_fiberinwith_stack_dyn(funx->x)(fune->raisee)effcdvf();;endtype'ainner={mutableroot:'aModes.Portable.t[@atomic];current:'aor_nullRuntime_dynamic.t}type'at='ainnerModes.Contended.tletmakea:_t={contended={root={portable=a};current=Runtime_dynamic.makeNull}};;letset_root(typea:valuemodcontended)(t:at)v=Atomic.Loc.set[%atomic.loct.contended.root]{portable=v};;letget(t:_t)=matchRuntime_dynamic.gett.contended.currentwith|Thisr->r|Null->(Atomic.Loc.get[%atomic.loct.contended.root]).portable;;letwith_temporarily(t:_t)v~f=Runtime_dynamic.with_temporarilyt.contended.current(Thisv)~f;;endexternaldynamic_supported:unit->bool="basement_dynamic_supported"include(valifdynamic_supported()then(moduleFiber_dynamic:Dynamic)else(moduleNon_fiber_dynamic:Dynamic))