diff --git a/include/tr/event_dispatcher.h b/include/tr/event_dispatcher.h
index 62a36e5..6585974 100644
--- a/include/tr/event_dispatcher.h
+++ b/include/tr/event_dispatcher.h
@@ -48,11 +48,10 @@ TR_CLASS(TR_EventDispatcher) {
TR_EXTENDS(TR_EventSubject);
TR_Queue events;
+ TR_Queue pending;
TR_Hash handler;
TR_EventHandler default_handler;
int running;
- int pollinterval; // milliseconds
- int nextpoll; // milliseconds
int heartbeat; // milliseconds
int nextbeat; // milliseconds
TR_EventDispatcherMode mode;
@@ -72,12 +71,13 @@ void TR_eventDispatcherRegisterHandler(TR_EventDispatcher, TR_EventHandler);
void TR_eventDispatcherSetHeartbeat(TR_EventDispatcher, int);
int TR_eventDispatcherGetBeatTime(TR_EventDispatcher);
int TR_eventDispatcherGetDataWaitTime(TR_EventDispatcher);
-void TR_eventDispatcherUpdateNextPoll(TR_EventDispatcher);
void TR_eventDispatcherStart(TR_EventDispatcher);
void TR_eventDispatcherShutdown(TR_EventDispatcher);
#define TR_eventDispatcherEnqueueEvent(disp,ev) \
(TR_queuePut((disp)->events, (ev)))
+#define TR_eventDispatcherEnqueuePending(disp,ev) \
+ (TR_queuePut((disp)->pending, (ev)))
#define TR_eventDispatcherStop(disp) \
(((TR_EventDispatcher)disp)->running = 0)
diff --git a/src/Makefile.am b/src/Makefile.am
index 5f3f0b4..e77d6d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,6 @@ TREVENT = event.c \
event_dispatcher_set_hearbeat.c \
event_dispatcher_get_beat_time.c \
event_dispatcher_get_data_wait_time.c \
- event_dispatcher_update_next_poll.c \
event_dispatcher_start.c \
event_dispatcher_shutdown.c \
event_handler.c \
diff --git a/src/event_dispatcher.c b/src/event_dispatcher.c
index bc1c9b5..5987452 100644
--- a/src/event_dispatcher.c
+++ b/src/event_dispatcher.c
@@ -64,22 +64,15 @@ static
int
eventDispatcherCtor(void * _this, va_list * params) {
TR_EventDispatcher this = _this;
- struct timespec tp;
- int now; // milliseconds
this->events = TR_new(TR_Queue);
+ this->pending = TR_new(TR_Queue);
this->handler = TR_new(TR_Hash);
this->mode = va_arg(*params, TR_EventDispatcherMode);
this->default_handler = va_arg(*params, TR_EventHandler);
this->running = 0;
this->heartbeat = 0;
this->nextbeat = 0;
- this->pollinterval = va_arg(*params, int);
-
- clock_gettime(CLOCK_REALTIME, &tp);
- now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
-
- this->nextpoll = now + this->pollinterval;
if (! _TR_controlDispatcher) {
_TR_controlDispatcher = this;
@@ -105,6 +98,7 @@ eventDispatcherDtor(void * _this) {
TR_hashCleanup(this->handler);
TR_delete(this->handler);
+ TR_delete(this->pending);
TR_delete(this->events);
}
diff --git a/src/event_dispatcher_start.c b/src/event_dispatcher_start.c
index 8a1f927..13dedb7 100644
--- a/src/event_dispatcher_start.c
+++ b/src/event_dispatcher_start.c
@@ -53,11 +53,18 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
(TR_EventSubject)this,
TR_DISPATCHER_EVENT_HEARTBEAT,
NULL);
- } else if (TR_queueEmpty(this->events) || this->nextpoll <= now) {
+ } else if (TR_queueEmpty(this->events)) {
int evtid = TR_EVD_CLIENT == this->mode
? TR_DISPATCHER_EVENT_USER_WAIT
: TR_DISPATCHER_EVENT_DATA_WAIT;
- int * toutptr = TR_queueEmpty(this->events) ? NULL : &ZERO;
+ int * toutptr = NULL;
+
+ if (! TR_queueEmpty(this->pending)) {
+ toutptr = &ZERO;
+ TR_delete(this->events);
+ this->events = this->pending;
+ this->pending = TR_new(TR_Queue);
+ }
event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, toutptr);
} else {
@@ -91,7 +98,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
if (TR_EVENT_DONE == done) {
TR_delete(event);
} else {
- TR_eventDispatcherEnqueueEvent(this, event);
+ TR_eventDispatcherEnqueuePending(this, event);
}
}
}
diff --git a/src/event_dispatcher_update_next_poll.c b/src/event_dispatcher_update_next_poll.c
deleted file mode 100644
index b7f9b2e..0000000
--- a/src/event_dispatcher_update_next_poll.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * \file
- *
- * \author Georg Hopp
- *
- * \copyright
- * Copyright © 2014 Georg Hopp
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include
-
-#include "trbase.h"
-
-#include "tr/event_dispatcher.h"
-
-void
-TR_eventDispatcherUpdateNextPoll(TR_EventDispatcher this)
-{
- struct timespec tp;
- int now; // milliseconds
-
- clock_gettime(CLOCK_REALTIME, &tp);
- now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
-
- while(this->nextpoll <= now) this->nextpoll += this->pollinterval;
-}
-
-// vim: set ts=4 sw=4: