From 0c41866c9a0fcdf7c3e8f8fc012a60b42962dc40 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 3 Sep 2024 09:18:13 -0400 Subject: [PATCH] wip: move Chan to sync, use events --- src/core/moonpool.ml | 1 - src/core/moonpool.mli | 1 - src/{core => sync}/chan.ml | 17 ++++++++++++----- src/{core => sync}/chan.mli | 10 ++++++++++ src/sync/moonpool_sync.ml | 3 ++- 5 files changed, 24 insertions(+), 8 deletions(-) rename src/{core => sync}/chan.ml (93%) rename src/{core => sync}/chan.mli (87%) diff --git a/src/core/moonpool.ml b/src/core/moonpool.ml index 47e5e5e3..0bf450e5 100644 --- a/src/core/moonpool.ml +++ b/src/core/moonpool.ml @@ -22,7 +22,6 @@ module Atomic = Atomic_ module Blocking_queue = Bb_queue module Background_thread = Background_thread module Bounded_queue = Bounded_queue -module Chan = Chan module Exn_bt = Exn_bt module Fifo_pool = Fifo_pool module Fut = Fut diff --git a/src/core/moonpool.mli b/src/core/moonpool.mli index a992e8b8..041f3de7 100644 --- a/src/core/moonpool.mli +++ b/src/core/moonpool.mli @@ -80,7 +80,6 @@ val await : 'a Fut.t -> 'a module Lock = Lock module Fut = Fut -module Chan = Chan module Task_local_storage = Task_local_storage module Thread_local_storage = Thread_local_storage diff --git a/src/core/chan.ml b/src/sync/chan.ml similarity index 93% rename from src/core/chan.ml rename to src/sync/chan.ml index 5ce82376..8e596375 100644 --- a/src/core/chan.ml +++ b/src/sync/chan.ml @@ -1,4 +1,5 @@ -module A = Atomic_ +open Moonpool +module A = Moonpool_private.Atomic_ type 'a or_error = 'a Fut.or_error type 'a waiter = 'a Fut.promise @@ -97,7 +98,7 @@ let push (self : _ t) x : unit = true | Elems q -> not (A.compare_and_set self.st old_st (Elems (Q.push q x))) do - Domain_.relax () + Moonpool_private.Domain_.relax () done let try_pop (type elt) self : elt option = @@ -115,7 +116,7 @@ let try_pop (type elt) self : elt option = if A.compare_and_set self.st old_st new_st then raise_notrace (M.Found x) else - Domain_.relax () + Moonpool_private.Domain_.relax () | _ -> raise_notrace Exit done; None @@ -152,7 +153,7 @@ let pop (type elt) (self : _ t) : elt Fut.t = raise_notrace (M.Fut fut)); true do - Domain_.relax () + Moonpool_private.Domain_.relax () done; (* never reached *) assert false @@ -180,7 +181,7 @@ let close (self : _ t) : unit = ) else true do - Domain_.relax () + Moonpool_private.Domain_.relax () done [@@@ifge 5.0] @@ -190,4 +191,10 @@ let pop_await self = | Some x -> x | None -> Fut.await @@ pop self +let[@inline] pop_ev self : _ Event.t = + Event.from_request { + request=fun comp k -> + + } + [@@@endif] diff --git a/src/core/chan.mli b/src/sync/chan.mli similarity index 87% rename from src/core/chan.mli rename to src/sync/chan.mli index 083cf8d5..9c86cb18 100644 --- a/src/core/chan.mli +++ b/src/sync/chan.mli @@ -9,6 +9,8 @@ @since 0.3 *) +open Moonpool + type 'a or_error = 'a Fut.or_error type 'a t @@ -49,4 +51,12 @@ val pop_await : 'a t -> 'a available. See {!Fut.await} for more details. @since 0.3 *) +val pop_ev : 'a t -> 'a Event.t +(** Pop from the channel, as an event. + @since NEXT_RELEASE *) + +val push_ev : 'a t -> 'a -> unit Event.t +(** Push into the channel, as an event. + @since NEXT_RELEASE *) + [@@@endif] diff --git a/src/sync/moonpool_sync.ml b/src/sync/moonpool_sync.ml index 2c5fe741..44a28b99 100644 --- a/src/sync/moonpool_sync.ml +++ b/src/sync/moonpool_sync.ml @@ -1,9 +1,10 @@ module Mutex = Picos_std_sync.Mutex module Condition = Picos_std_sync.Condition module Lock = Lock -module Event = Picos_std_event +module Event = Event module Semaphore = Picos_std_sync.Semaphore module Lazy = Picos_std_sync.Lazy module Latch = Picos_std_sync.Latch module Ivar = Picos_std_sync.Ivar module Stream = Picos_std_sync.Stream +module Chan = Chan