]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
[eventloop] Added asap events to support delayed callbacks.
authorJean-Sebastien Legare <jean-sebastien.legare@citrix.com>
Wed, 22 Jul 2009 09:38:57 +0000 (02:38 -0700)
committerJean-Sebastien Legare <jean-sebastien.legare@citrix.com>
Fri, 24 Jul 2009 14:48:04 +0000 (07:48 -0700)
This adds a call "start_timer_asap" which behaves as if a timer had
been added with a trigger time == now.

libs/stdext/eventloop.ml
libs/stdext/eventloop.mli

index b514fa9e3a5bf33a7e28023d52fd95239f8930ee..8d69a4cd3364c57b51fe2033e52181855e9aa572 100644 (file)
@@ -20,7 +20,7 @@ let dbg fmt =
        Printf.ksprintf logger fmt
 
 module ConnMap = Map.Make (struct type t = Unix.file_descr let compare = compare end)
-
+       
 (* A module that supports finding a timer by handle as well as by expiry time. *)
 module Timers = struct
 
@@ -229,6 +229,9 @@ let start_timer t time_offset_sec cb =
        let at = Unix.gettimeofday () +. time_offset_sec in
        Timers.add_timer t.timers at cb
 
+let start_timer_asap t cb =
+       Timers.add_timer t.timers t.current_time cb
+
 let start_periodic_timer t time_offset_sec period cb =
        let orig_timer = ref (None: timer option) in
        let resubmit_timer_closure () = 
index edaa2a4eb5385c6d164791eab0d8240b8009a96e..6e57991908ca4e03783bc8c40eca53bc1be6e254 100644 (file)
@@ -64,6 +64,12 @@ type timer
 *)
 val start_timer : t -> float (* offset, secs *) -> (unit -> unit) -> timer
 
+(** Enqueues an event that will be invoked in the next event loop
+    iteration.  This behaves as if a timer had been set to fire with
+    "now" as the trigger time.
+*)
+val start_timer_asap : t -> (unit -> unit) -> timer
+
 (** Starts a timer that will fire periodically. The timer needs
     explicit cancellation.     
 *)