From: Jean-Sebastien Legare Date: Wed, 22 Jul 2009 09:38:57 +0000 (-0700) Subject: [eventloop] Added asap events to support delayed callbacks. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a74fa78ba1346fa19327623597ea5f81e7e038a7;p=xenclient%2Ftoolstack.git [eventloop] Added asap events to support delayed callbacks. This adds a call "start_timer_asap" which behaves as if a timer had been added with a trigger time == now. --- diff --git a/libs/stdext/eventloop.ml b/libs/stdext/eventloop.ml index b514fa9..8d69a4c 100644 --- a/libs/stdext/eventloop.ml +++ b/libs/stdext/eventloop.ml @@ -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 () = diff --git a/libs/stdext/eventloop.mli b/libs/stdext/eventloop.mli index edaa2a4..6e57991 100644 --- a/libs/stdext/eventloop.mli +++ b/libs/stdext/eventloop.mli @@ -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. *)