# HG changeset patch # User Rob Hoes CA-40030: Option to remove an event by name from the periodic scheduler Signed-off-by: Rob Hoes diff -r b9d60623be93 ocaml/xapi/ipq.ml --- a/ocaml/xapi/ipq.ml Fri Apr 09 12:46:19 2010 +0100 +++ b/ocaml/xapi/ipq.ml Fri Apr 09 14:08:56 2010 +0100 @@ -92,7 +92,15 @@ | m -> if ev = h.data.(n).ev then n else iter (n-1) in iter (h.size-1) - + +let find_p h f = + let rec iter n = + match n with + -1 -> -1 + | m -> if f h.data.(n).ev then n else iter (n-1) + in + iter (h.size-1) + let pop_maximum h = let m = maximum h in remove h 0; m let iter f h = diff -r b9d60623be93 ocaml/xapi/xapi_periodic_scheduler.ml --- a/ocaml/xapi/xapi_periodic_scheduler.ml Fri Apr 09 12:46:19 2010 +0100 +++ b/ocaml/xapi/xapi_periodic_scheduler.ml Fri Apr 09 14:08:56 2010 +0100 @@ -36,6 +36,12 @@ Ipq.add queue { Ipq.ev={ func=newfunc; ty=ty; name=name}; Ipq.time=((Unix.gettimeofday ()) +. start) }); if signal then Delay.signal delay +let remove_from_queue name = + debug "Removing function %s from queue" name; + let index = Ipq.find_p queue (fun {name=n} -> name = n) in + if index > -1 then + Ipq.remove queue index + let loop () = debug "Periodic scheduler started"; while true do diff -r b9d60623be93 ocaml/xapi/xapi_periodic_scheduler.mli --- a/ocaml/xapi/xapi_periodic_scheduler.mli Fri Apr 09 12:46:19 2010 +0100 +++ b/ocaml/xapi/xapi_periodic_scheduler.mli Fri Apr 09 14:08:56 2010 +0100 @@ -22,6 +22,9 @@ val add_to_queue : ?signal:bool -> string -> func_ty -> float -> (unit -> unit) -> unit +(** Remove a scheduled item by name *) +val remove_from_queue : string -> unit + (** The scheduler's main loop, started by {!Xapi} on start-up. *) val loop : unit -> unit