Permalink
Browse files

caller is responsible for dropping ref to cancel after use

  • Loading branch information...
1 parent f5fad76 commit 747fd350240a16aebe53b467eadc6ac427bee726 Jake Donham committed Apr 22, 2010
Showing with 22 additions and 16 deletions.
  1. +7 −6 src/froc/froc.ml
  2. +9 −7 src/froc/froc.mli
  3. +3 −1 src/froc/froc_ddg.ml
  4. +3 −2 src/froc/froc_ddg.mli
View
@@ -66,10 +66,10 @@ let send_exn s e = send_result s (Fail e)
let notify_result_e_cancel t f =
match repr_of_event t with
- | Never -> ignore
+ | Never -> no_cancel
| Occurs o ->
let dl = Dlist.add_after o.e_deps f in
- fun () -> Dlist.remove dl
+ make_cancel (fun () -> Dlist.remove dl)
let notify_result_e t f =
let cancel = notify_result_e_cancel t f in
@@ -93,14 +93,15 @@ let hash_event t =
| Occurs o -> o.e_id
let next t =
+<<<<<<< HEAD:src/froc/froc.ml
let t', s' = make_event () in
- let c = ref (ignore in
+ let c = ref no_cancel in
c :=
notify_result_e_cancel t
(fun r ->
cancel !c;
- c := ignore;
- send_result s' r;
+ c := no_cancel;
+ send_result s r;
(* XXX future deps are still added; would be better to become Never *)
Dlist.clear (occurs_of_event_sender s').e_deps);
t'
@@ -194,7 +195,7 @@ let switch_be ?eq b e =
notify_result_e e
(function
| Value b -> cancel !c; c := connect_cancel bu b
- | Fail e -> cancel !c; write_exn bu e);
+ | Fail e -> cancel !c; c := no_cancel; write_exn bu e);
bt
let until ?eq b e = switch_be ?eq b (next e)
View
@@ -48,6 +48,15 @@
val init : unit -> unit
(** Initialize the library. Must be called before any other function. *)
+type cancel
+ (** Type of handles to listener registrations. *)
+
+val no_cancel : cancel
+ (** Dummy cancel. *)
+
+val cancel : cancel -> unit
+ (** Cancels a listener registration using the given handle. *)
+
(** {2 Behaviors} *)
type 'a behavior
@@ -136,13 +145,6 @@ val read_result : 'a behavior -> 'a result
an exception.
*)
-type cancel
- (** Type of handles to listener registrations. *)
-
-val cancel : cancel -> unit
- (** Cancels a listener registration using the given handle. *)
-
-
val notify_b : 'a behavior -> ('a -> unit) -> unit
(**
Adds a listener for the value of a behavior, which is called
View
@@ -117,14 +117,16 @@ let read t =
| Fail e -> raise e
type cancel = unit -> unit
+let make_cancel f = f
+let no_cancel = ignore
let cancel c = c ()
let add_dep_cancel t f =
match repr_of_t t with
| Constant _ -> ignore
| Changeable c ->
let dl = Dlist.add_after c.deps f in
- fun () -> Dlist.remove dl
+ make_cancel (fun () -> Dlist.remove dl)
let add_dep ts t dep =
let cancel = add_dep_cancel t dep in
View
@@ -51,13 +51,14 @@ val connect : 'a u -> 'a t -> unit
val cleanup : (unit -> unit) -> unit
type cancel = unit -> unit
+val make_cancel : (unit -> unit) -> cancel
+val no_cancel : cancel
+val cancel : cancel -> unit
val notify_cancel : 'a t -> ('a -> unit) -> cancel
val notify_result_cancel : 'a t -> ('a result -> unit) -> cancel
val connect_cancel : 'a u -> 'a t -> cancel
-val cancel : cancel -> unit
-
val make_changeable : ?eq:('a -> 'a -> bool) -> ?result:'a result -> unit -> 'a t * 'a u
val make_constant : 'a result -> 'a t

0 comments on commit 747fd35

Please sign in to comment.