123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354(* This file is part of Luv, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *)typet=C.Types.Thread.tCtypes.ptrletself()=Ctypes.addr(C.Functions.Thread.self())letequal=C.Functions.Thread.equalletthread_trampoline=C.Functions.Thread.get_trampoline()letmake_thread_optionsstack_size=letmoduleO=C.Types.Thread.Optionsinletoptions=Ctypes.makeO.tinbeginmatchstack_sizewith|None->Ctypes.setfoptionsO.flagsO.no_flags|Somen->Ctypes.setfoptionsO.flagsO.has_stack_size;Ctypes.setfoptionsO.stack_size(Unsigned.Size_t.of_intn)end;Ctypes.addroptionsletcreate?stack_sizef=letthread=Ctypes.addr(Ctypes.makeC.Types.Thread.t)inletf=Error.catch_exceptionsfinletf_gc_root=Ctypes.Root.createfinletresult=C.Functions.Thread.createthread(make_thread_optionsstack_size)thread_trampolinef_gc_rootinifresult<0thenbeginCtypes.Root.releasef_gc_root;Error.result_from_cresultendelseResult.Okthreadletcreate_c?stack_size?(argument=Nativeint.zero)f=letthread=Ctypes.addr(Ctypes.makeC.Types.Thread.t)inC.Functions.Thread.create_cthread(make_thread_optionsstack_size)fargument|>Error.to_resultthreadletjointhread=C.Blocking.Thread.jointhread|>Error.to_result()