… | |
… | |
472 | given time, and optionally repeating in regular intervals after that. |
472 | given time, and optionally repeating in regular intervals after that. |
473 | |
473 | |
474 | The timers are based on real time, that is, if you register an event that |
474 | The timers are based on real time, that is, if you register an event that |
475 | times out after an hour and you reset your system clock to last years |
475 | times out after an hour and you reset your system clock to last years |
476 | time, it will still time out after (roughly) and hour. "Roughly" because |
476 | time, it will still time out after (roughly) and hour. "Roughly" because |
477 | detecting time jumps is hard, and soem inaccuracies are unavoidable (the |
477 | detecting time jumps is hard, and some inaccuracies are unavoidable (the |
478 | monotonic clock option helps a lot here). |
478 | monotonic clock option helps a lot here). |
479 | |
479 | |
480 | The relative timeouts are calculated relative to the C<ev_now ()> |
480 | The relative timeouts are calculated relative to the C<ev_now ()> |
481 | time. This is usually the right thing as this timestamp refers to the time |
481 | time. This is usually the right thing as this timestamp refers to the time |
482 | of the event triggering whatever timeout you are modifying/starting. If |
482 | of the event triggering whatever timeout you are modifying/starting. If |
483 | you suspect event processing to be delayed and you *need* to base the timeout |
483 | you suspect event processing to be delayed and you I<need> to base the timeout |
484 | on the current time, use something like this to adjust for this: |
484 | on the current time, use something like this to adjust for this: |
485 | |
485 | |
486 | ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
486 | ev_timer_set (&timer, after + ev_now () - ev_time (), 0.); |
|
|
487 | |
|
|
488 | The callback is guarenteed to be invoked only when its timeout has passed, |
|
|
489 | but if multiple timers become ready during the same loop iteration then |
|
|
490 | order of execution is undefined. |
487 | |
491 | |
488 | =over 4 |
492 | =over 4 |
489 | |
493 | |
490 | =item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat) |
494 | =item ev_timer_init (ev_timer *, callback, ev_tstamp after, ev_tstamp repeat) |
491 | |
495 | |
… | |
… | |
538 | again). |
542 | again). |
539 | |
543 | |
540 | They can also be used to implement vastly more complex timers, such as |
544 | They can also be used to implement vastly more complex timers, such as |
541 | triggering an event on eahc midnight, local time. |
545 | triggering an event on eahc midnight, local time. |
542 | |
546 | |
|
|
547 | As with timers, the callback is guarenteed to be invoked only when the |
|
|
548 | time (C<at>) has been passed, but if multiple periodic timers become ready |
|
|
549 | during the same loop iteration then order of execution is undefined. |
|
|
550 | |
543 | =over 4 |
551 | =over 4 |
544 | |
552 | |
545 | =item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb) |
553 | =item ev_periodic_init (ev_periodic *, callback, ev_tstamp at, ev_tstamp interval, reschedule_cb) |
546 | |
554 | |
547 | =item ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb) |
555 | =item ev_periodic_set (ev_periodic *, ev_tstamp after, ev_tstamp repeat, reschedule_cb) |
548 | |
556 | |
549 | Lots of arguments, lets sort it out... There are basically three modes of |
557 | Lots of arguments, lets sort it out... There are basically three modes of |
550 | operation, and we will explain them from simplest to complex: |
558 | operation, and we will explain them from simplest to complex: |
551 | |
|
|
552 | |
559 | |
553 | =over 4 |
560 | =over 4 |
554 | |
561 | |
555 | =item * absolute timer (interval = reschedule_cb = 0) |
562 | =item * absolute timer (interval = reschedule_cb = 0) |
556 | |
563 | |