1234567891011121314151617181920212223242526272829303132333435363738394041424344(* This file is part of Lwt, released under the MIT license. See LICENSE.md for
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)(* [Lwt_sequence] is deprecated – we don't want users outside Lwt using it.
However, it is still used internally by Lwt. So, briefly disable warning 3
("deprecated"), and create a local, non-deprecated alias for
[Lwt_sequence] that can be referred to by the rest of the code in this
module without triggering any more warnings. *)[@@@ocaml.warning"-3"]moduleLwt_sequence=Lwt_sequence[@@@ocaml.warning"+3"]openLwt.Infixtypet={mutablelocked:bool;waiters:unitLwt.uLwt_sequence.t}letcreate()={locked=false;waiters=Lwt_sequence.create()}letlockm=ifm.lockedthen(Lwt.add_task_r[@ocaml.warning"-3"])m.waiterselsebeginm.locked<-true;Lwt.return_unitendletunlockm=ifm.lockedthenbeginifLwt_sequence.is_emptym.waitersthenm.locked<-falseelse(* We do not use [Lwt.wakeup] here to avoid a stack overflow
when unlocking a lot of threads. *)Lwt.wakeup_later(Lwt_sequence.take_lm.waiters)()endletwith_lockmf=lockm>>=fun()->Lwt.finalizef(fun()->unlockm;Lwt.return_unit)letis_lockedm=m.lockedletis_emptym=Lwt_sequence.is_emptym.waiters