@@ -84,6 +84,8 @@ let notifiers = Domain_map.create_protected_map ()
8484 https://github.com/ocsigen/lwt/pull/278. *)
8585let current_notification_id = Atomic. make (0x7FFFFFFF - 1000 )
8686
87+ type notification_id = Domain .id * int
88+
8789let make_notification ?(once =false ) domain_id f =
8890 let id = Atomic. fetch_and_add current_notification_id 1 in
8991 Domain_map. update notifiers domain_id
@@ -95,17 +97,17 @@ let make_notification ?(once=false) domain_id f =
9597 | Some notifiers ->
9698 Notifiers. add notifiers id { notify_once = once; notify_handler = f };
9799 Some notifiers);
98- id
100+ (domain_id, id)
99101
100- let stop_notification domain_id id =
102+ let stop_notification ( domain_id , id ) =
101103 Domain_map. update notifiers domain_id
102104 (function
103105 | None -> None
104106 | Some notifiers ->
105107 Notifiers. remove notifiers id;
106108 Some notifiers)
107109
108- let set_notification domain_id id f =
110+ let set_notification ( domain_id , id ) f =
109111 Domain_map. update notifiers domain_id
110112 (function
111113 | None -> raise Not_found
@@ -114,7 +116,7 @@ let set_notification domain_id id f =
114116 Notifiers. replace notifiers id { notifier with notify_handler = f };
115117 Some notifiers)
116118
117- let call_notification domain_id id =
119+ let call_notification ( domain_id , id ) =
118120 match Domain_map. find notifiers domain_id with
119121 | None -> ()
120122 | Some notifiers ->
@@ -209,7 +211,7 @@ let run_job_aux async_method job result =
209211 jobs in
210212 ignore begin
211213 (* Create the notification for asynchronous wakeup. *)
212- let id =
214+ let (_, notifid) as id =
213215 make_notification ~once: true domain_id
214216 (fun () ->
215217 Lwt_sequence. remove node;
@@ -220,7 +222,7 @@ let run_job_aux async_method job result =
220222 notification. *)
221223 Lwt. pause () >> = fun () ->
222224 (* The job has terminated, send the result immediately. *)
223- if check_job job id then call_notification domain_id id;
225+ if check_job job notifid then call_notification id;
224226 Lwt. return_unit
225227 end;
226228 waiter
@@ -2199,11 +2201,12 @@ let tcflow ch act =
21992201
22002202external init_notification : Domain .id -> Unix .file_descr = " lwt_unix_init_notification_stub"
22012203external send_notification : Domain .id -> int -> unit = " lwt_unix_send_notification_stub"
2204+ let send_notification (d , n ) = send_notification d n
22022205external recv_notifications : Domain .id -> int array = " lwt_unix_recv_notifications_stub"
22032206
22042207let handle_notifications (_ : Lwt_engine.event ) =
22052208 let domain_id = Domain. self () in
2206- Array. iter (call_notification domain_id) (recv_notifications domain_id)
2209+ Array. iter (fun n -> call_notification ( domain_id, n) ) (recv_notifications domain_id)
22072210
22082211let event_notifications =
22092212 Domain.DLS. new_key (fun () ->
@@ -2247,8 +2250,8 @@ type signal_handler = {
22472250
22482251and signal_handler_id = signal_handler option ref
22492252
2250- (* TODO: what to do about signals? *)
2251- let signals = ref Signal_map. empty
2253+ (* TODO: make parallel safe *)
2254+ let signals : ((Domain.id * int) * ((signal_handler_id -> file_perm -> unit) Lwt_sequence.t) ) Signal_map.t ref = ref Signal_map. empty
22522255let signal_count () =
22532256 Signal_map. fold
22542257 (fun _signum (_id , actions ) len -> len + Lwt_sequence. length actions)
@@ -2262,17 +2265,17 @@ let on_signal_full signum handler =
22622265 Signal_map. find signum ! signals
22632266 with Not_found ->
22642267 let actions = Lwt_sequence. create () in
2265- let notification =
2268+ let (_, notifid) as notification =
22662269 make_notification (Domain. self () )
22672270 (fun () ->
22682271 Lwt_sequence. iter_l
22692272 (fun f -> f id signum)
22702273 actions)
22712274 in
22722275 (try
2273- set_signal signum notification
2276+ set_signal signum notifid
22742277 with exn when Lwt.Exception_filter. run exn ->
2275- stop_notification ( Domain. self () ) notification;
2278+ stop_notification notification;
22762279 raise exn );
22772280 signals := Signal_map. add signum (notification, actions) ! signals;
22782281 (notification, actions)
@@ -2294,13 +2297,13 @@ let disable_signal_handler id =
22942297 if Lwt_sequence. is_empty actions then begin
22952298 remove_signal sh.sh_num;
22962299 signals := Signal_map. remove sh.sh_num ! signals;
2297- stop_notification ( Domain. self () ) notification
2300+ stop_notification notification
22982301 end
22992302
23002303let reinstall_signal_handler signum =
23012304 match Signal_map. find signum ! signals with
23022305 | exception Not_found -> ()
2303- | notification , _ ->
2306+ | ( _ , notification ) , _ ->
23042307 set_signal signum notification
23052308
23062309(* +-----------------------------------------------------------------+
0 commit comments