Commit 8fb778937b2649eb44ebf01d06450c18d2009905
1 parent
f6254dfb
add function to update next poll timer externally.
Showing
4 changed files
with
43 additions
and
1 deletions
@@ -72,6 +72,7 @@ void TR_eventDispatcherRegisterHandler(TR_EventDispatcher, TR_EventHandler); | @@ -72,6 +72,7 @@ void TR_eventDispatcherRegisterHandler(TR_EventDispatcher, TR_EventHandler); | ||
72 | void TR_eventDispatcherSetHeartbeat(TR_EventDispatcher, int); | 72 | void TR_eventDispatcherSetHeartbeat(TR_EventDispatcher, int); |
73 | int TR_eventDispatcherGetBeatTime(TR_EventDispatcher); | 73 | int TR_eventDispatcherGetBeatTime(TR_EventDispatcher); |
74 | int TR_eventDispatcherGetDataWaitTime(TR_EventDispatcher); | 74 | int TR_eventDispatcherGetDataWaitTime(TR_EventDispatcher); |
75 | +void TR_eventDispatcherUpdateNextPoll(TR_EventDispatcher); | ||
75 | void TR_eventDispatcherStart(TR_EventDispatcher); | 76 | void TR_eventDispatcherStart(TR_EventDispatcher); |
76 | void TR_eventDispatcherShutdown(TR_EventDispatcher); | 77 | void TR_eventDispatcherShutdown(TR_EventDispatcher); |
77 | 78 |
@@ -9,6 +9,7 @@ TREVENT = event.c \ | @@ -9,6 +9,7 @@ TREVENT = event.c \ | ||
9 | event_dispatcher_set_hearbeat.c \ | 9 | event_dispatcher_set_hearbeat.c \ |
10 | event_dispatcher_get_beat_time.c \ | 10 | event_dispatcher_get_beat_time.c \ |
11 | event_dispatcher_get_data_wait_time.c \ | 11 | event_dispatcher_get_data_wait_time.c \ |
12 | + event_dispatcher_update_next_poll.c \ | ||
12 | event_dispatcher_start.c \ | 13 | event_dispatcher_start.c \ |
13 | event_dispatcher_shutdown.c \ | 14 | event_dispatcher_shutdown.c \ |
14 | event_handler.c \ | 15 | event_handler.c \ |
@@ -63,7 +63,6 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -63,7 +63,6 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
63 | : TR_DISPATCHER_EVENT_DATA_WAIT; | 63 | : TR_DISPATCHER_EVENT_DATA_WAIT; |
64 | int * toutptr = TR_queueEmpty(this->events) ? NULL : &ZERO; | 64 | int * toutptr = TR_queueEmpty(this->events) ? NULL : &ZERO; |
65 | 65 | ||
66 | - this->nextpoll += this->pollinterval; | ||
67 | event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, toutptr); | 66 | event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, toutptr); |
68 | } else { | 67 | } else { |
69 | event = TR_queueGet(this->events); | 68 | event = TR_queueGet(this->events); |
src/event_dispatcher_update_next_poll.c
0 → 100644
1 | +/** | ||
2 | + * \file | ||
3 | + * | ||
4 | + * \author Georg Hopp | ||
5 | + * | ||
6 | + * \copyright | ||
7 | + * Copyright © 2014 Georg Hopp | ||
8 | + * | ||
9 | + * This program is free software: you can redistribute it and/or modify | ||
10 | + * it under the terms of the GNU General Public License as published by | ||
11 | + * the Free Software Foundation, either version 3 of the License, or | ||
12 | + * (at your option) any later version. | ||
13 | + * | ||
14 | + * This program is distributed in the hope that it will be useful, | ||
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | + * GNU General Public License for more details. | ||
18 | + * | ||
19 | + * You should have received a copy of the GNU General Public License | ||
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | + */ | ||
22 | + | ||
23 | +#include <time.h> | ||
24 | + | ||
25 | +#include "trbase.h" | ||
26 | + | ||
27 | +#include "tr/event_dispatcher.h" | ||
28 | + | ||
29 | +void | ||
30 | +TR_eventDispatcherUpdateNextPoll(TR_EventDispatcher this) | ||
31 | +{ | ||
32 | + struct timespec tp; | ||
33 | + int now; // milliseconds | ||
34 | + | ||
35 | + clock_gettime(CLOCK_REALTIME, &tp); | ||
36 | + now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; | ||
37 | + | ||
38 | + while(this->nextpoll <= now) this->nextpoll += this->pollinterval; | ||
39 | +} | ||
40 | + | ||
41 | +// vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment