123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(* 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. *)includeC.Functions.Looptypet=C.Types.Loop.tCtypes.ptrletinit()=letloop=Ctypes.addr(Ctypes.makeC.Types.Loop.t)inletresult=C.Functions.Loop.initloopinError.to_resultloopresultletconfigureloopoptionvalue=C.Functions.Loop.configureloopoption(Obj.magicvalue)|>Error.to_result()letcloseloop=C.Functions.Loop.closeloop|>Error.to_result()letor_defaultmaybe_loop=matchmaybe_loopwith|Someloop->loop|None->C.Functions.Loop.default()moduleRun_mode=C.Types.Loop.Run_modemoduleOption=structincludeC.Types.Loop.Optiontype'valuet=intend(* run must always release the runtime lock, even if called with
Run_mode.nowait. This is because calling run can trigger callbacks, and
callbacks expect to be able to take the lock (eventually). If the lock is
*not* released by run and a callback is called, there will be a deadlock. *)letrun?loop?(mode=`DEFAULT)()=letloop=or_defaultloopinC.Blocking.Loop.runloopmodeletbackend_fdloop=letresult=C.Functions.Loop.backend_fdloopinifresult>=0thenSomeresultelseNoneletbackend_timeoutloop=letresult=C.Functions.Loop.backend_timeoutloopinifresult>=0thenSomeresultelseNoneletforkloop=C.Functions.Loop.forkloop|>Error.to_result()letlibrary_shutdown=C.Functions.Loop.library_shutdown