mirror of
https://github.com/c-cube/nanoev.git
synced 2025-12-06 03:05:32 -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
|
Thread.join st.th
|
||||||
end
|
end
|
||||||
|
|
||||||
let has_bg_thread = Global_.has_bg_thread
|
module Background_thread = struct
|
||||||
let setup_bg_thread = Global_.setup_bg_thread
|
let is_setup = Global_.has_bg_thread
|
||||||
let shutdown_bg_thread = Global_.shutdown_bg_thread
|
let setup = Global_.setup_bg_thread
|
||||||
|
let shutdown = Global_.shutdown_bg_thread
|
||||||
|
|
||||||
let with_setup_bg_thread ev f =
|
let with_setup ev f =
|
||||||
setup_bg_thread ev;
|
setup ev;
|
||||||
Fun.protect ~finally:shutdown_bg_thread f
|
Fun.protect ~finally:shutdown f
|
||||||
|
end
|
||||||
|
|
||||||
let[@inline] get_loop_exn_ () : Nanoev.t =
|
let[@inline] get_loop_exn_ () : Nanoev.t =
|
||||||
match Atomic.get Global_.st with
|
match Atomic.get Global_.st with
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
(** Basic interface with picos *)
|
(** Basic interface with picos *)
|
||||||
|
|
||||||
module Background_thread : sig
|
module Background_thread : sig
|
||||||
val setup_bg_thread : Nanoev.t -> unit
|
val setup : Nanoev.t -> unit
|
||||||
(** Install this event loop in a background thread *)
|
(** Install this event loop in a background thread *)
|
||||||
|
|
||||||
val shutdown_bg_thread : unit -> unit
|
val shutdown : unit -> unit
|
||||||
(** Shutdown background thread, assuming {! has_bg_thread} returns [true] *)
|
(** 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
|
val is_setup : unit -> bool
|
||||||
(** [has_bg_thread ()] is [true] iff a background thread is running a nanoev
|
(** [is_setup()] is [true] iff a background thread is running a nanoev loop *)
|
||||||
loop *)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
(** {2 Non blocking IO primitives} *)
|
(** {2 Non blocking IO primitives} *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue