Fork 0

[core] Add li_waitqueue_set_delay() function

This commit is contained in:
Thomas Porzelt 2010-05-10 21:42:06 +02:00
parent de3515cd27
commit b3f8b8d62f
2 changed files with 14 additions and 1 deletions

View File

@ -29,12 +29,15 @@ struct liWaitQueue {
* li_waitqueue_push, li_waitqueue_pop and li_waitqueue_remove have O(1) complexity
/* initializes a waitqueue by creating and starting the ev_timer. precision is sub-seconds */
/* initializes a waitqueue by creating the ev_timer and initializing the queue. precision is sub-seconds */
LI_API void li_waitqueue_init(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB callback, gdouble delay, gpointer data);
/* stops the waitqueue. to restart it, simply call li_waitqueue_update */
LI_API void li_waitqueue_stop(liWaitQueue *queue);
/* updates the delay of the timer. if timer is active, it is stopped and restarted */
LI_API void li_waitqueue_set_delay(liWaitQueue *queue, gdouble delay);
/* updates the timeout of the waitqueue, you should allways call this at the end of your callback */
LI_API void li_waitqueue_update(liWaitQueue *queue);

View File

@ -14,6 +14,16 @@ void li_waitqueue_stop(liWaitQueue *queue) {
ev_timer_stop(queue->loop, &queue->timer);
void li_waitqueue_set_delay(liWaitQueue *queue, gdouble delay) {
if (ev_is_active(&queue->timer)) {
ev_timer_stop(queue->loop, &queue->timer);
ev_timer_set(&queue->timer, delay, delay);
ev_timer_start(queue->loop, &queue->timer);
} else {
ev_timer_set(&queue->timer, delay, delay);
void li_waitqueue_update(liWaitQueue *queue) {
ev_tstamp repeat;
ev_tstamp now = ev_now(queue->loop);