[timer_scheduler] is there any interest on a timer scheduler library?

Hi, I would like to be able to submit/schedule tasks at a given time (callouts) which could be oneshot or periodics. Something like the_timer_scheduler::schedule_at(t1_, now()+seconds(10)); Is there any interest on this feature? I have started to scketch the interface of the library. Note: I have used timeout because timer already exists in the boost namespace. callout could be also used if this is more clear. Note. This interface do not allow arbitrary callbacks functions. struct timeout; typedef void (*timeout_callback)(timeout&); struct timeout_type { timeout_type(timeout_callback callback); timeout_callback operator()(timeout&); }; struct timeout { timeout(const timeout_type& type); const timeout_type& type; // ... }; // template class that store in addition a context template <typename CTX, timeout_type& TYPE> struct timeout_ctx : timeout { timeout_ctx(CTX* ctx) : timeout(TYPE) , context_(ctx) {} CTX* context() {return context_;} CTX* operator CTX*() {return context_;} protected: CTX* context_; }; // there is a single timer scheduler namespace the_timer_scheduler { void schedule_at(timeout& handle, system_time& absolute_time); void reschedule_at(timeout& handle, system_time& absolute_time); void schedule_at_periodicaly(timeout& handle, system_time& absolute_time, duration_type period); void reschedule_at_periodicaly(timeout& handle, system_time& absolute_time, duration_type period); void cancel(timeout& handle); } Example: static const timeout_type t1_type; struct my_ctx, typedef timeout_ctx<my_ctx, t1_type> t1; struct my_ctx { my_ctx() : t1_(this) {} t1 t1_; void on_t1(); static void on_t1(timer* p) { static_cast<t1*>(p)->context()->on_t1(); } void funct() { the_timer_scheduler::schedule_at(t1_, now()+seconds(10)); // ... the_timer_scheduler::cancel(t1_); } }; timeout_type t1_type(ctx::on_t1); The implementation of the timeouts scheduler could be based on "Redesigning the BSD Callout and Timer Facilities" by Adam M. Costello, George Varghese http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=B5202FC949FF3EDB0E789F68F509950C?doi=10.1.1.54.6466&rep=rep1&type=pdf Vicente

On Mon, Nov 3, 2008 at 12:17 PM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
Hi,
I would like to be able to submit/schedule tasks at a given time (callouts) which could be oneshot or periodics. Something like
the_timer_scheduler::schedule_at(t1_, now()+seconds(10));
Is there any interest on this feature?
I have started to scketch the interface of the library.
How is it better than Asio's timer completion callbacks? -- gpd

----- Original Message ----- From: "Giovanni Piero Deretta" <gpderetta@gmail.com> To: <boost@lists.boost.org> Sent: Monday, November 03, 2008 12:36 PM Subject: Re: [boost] [timer_scheduler] is there any interest on a timerscheduler library?
On Mon, Nov 3, 2008 at 12:17 PM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
Hi,
I would like to be able to submit/schedule tasks at a given time (callouts) which could be oneshot or periodics. Something like
the_timer_scheduler::schedule_at(t1_, now()+seconds(10));
Is there any interest on this feature?
I have started to scketch the interface of the library.
How is it better than Asio's timer completion callbacks?
I don't think we can say it is better or worst. The timer_scheduler is a low level facility that could be used by the Asio's deadline_timer as TimerScheduler (with some adaptations of course), directly by the end user or by other general purpose library. One of the advantages could be the size of the code, the other could be the performances. I don't know all the details of the asio TimerScheduler implementation but it seems to me that most of the TimerScheduler operations depends on the number of running timers on the queue and so they are O(n). The implementation this will be based uses a weel which allows to have most of the operation in constant time. See the reference on the preceding mail for more information. Of course the asio library could implement implement directly a TimerScheduler based on this implementation. On the other side the timeout function is called from the timer_scheduler interruption thread and so some kind of synchronization could be needed by the user. Vicente
participants (2)
-
Giovanni Piero Deretta
-
vicente.botet