mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-05 19:00:35 -05:00
refactor picos: move whole setup into Background_thread mod
This commit is contained in:
parent
c2b7c0e39d
commit
14d744c369
2 changed files with 14 additions and 13 deletions
|
|
@ -66,13 +66,15 @@ module Global_ = struct
|
|||
Thread.join st.th
|
||||
end
|
||||
|
||||
let has_bg_thread = Global_.has_bg_thread
|
||||
let setup_bg_thread = Global_.setup_bg_thread
|
||||
let shutdown_bg_thread = Global_.shutdown_bg_thread
|
||||
module Background_thread = struct
|
||||
let is_setup = Global_.has_bg_thread
|
||||
let setup = Global_.setup_bg_thread
|
||||
let shutdown = Global_.shutdown_bg_thread
|
||||
|
||||
let with_setup_bg_thread ev f =
|
||||
setup_bg_thread ev;
|
||||
Fun.protect ~finally:shutdown_bg_thread f
|
||||
let with_setup ev f =
|
||||
setup ev;
|
||||
Fun.protect ~finally:shutdown f
|
||||
end
|
||||
|
||||
let[@inline] get_loop_exn_ () : Nanoev.t =
|
||||
match Atomic.get Global_.st with
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
(** Basic interface with picos *)
|
||||
|
||||
module Background_thread : sig
|
||||
val setup_bg_thread : Nanoev.t -> unit
|
||||
val setup : Nanoev.t -> unit
|
||||
(** Install this event loop in a background thread *)
|
||||
|
||||
val shutdown_bg_thread : unit -> unit
|
||||
(** Shutdown background thread, assuming {! has_bg_thread} returns [true] *)
|
||||
val shutdown : unit -> unit
|
||||
(** Shutdown background thread, assuming {! is_setup} returns [true] *)
|
||||
|
||||
val with_setup_bg_thread : Nanoev.t -> (unit -> 'a) -> 'a
|
||||
val with_setup : Nanoev.t -> (unit -> 'a) -> 'a
|
||||
|
||||
val has_bg_thread : unit -> bool
|
||||
(** [has_bg_thread ()] is [true] iff a background thread is running a nanoev
|
||||
loop *)
|
||||
val is_setup : unit -> bool
|
||||
(** [is_setup()] is [true] iff a background thread is running a nanoev loop *)
|
||||
end
|
||||
|
||||
(** {2 Non blocking IO primitives} *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue