wip: move Chan to sync, use events

This commit is contained in:
Simon Cruanes 2024-09-03 09:18:13 -04:00
parent 0b8415436f
commit 0c41866c9a
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
5 changed files with 24 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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]

View file

@ -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