Commit f6254dfb48838da1409f8fd846c5160065e79332
1 parent
a17bd09d
preparation for edge triggerd events
Showing
3 changed files
with
24 additions
and
15 deletions
@@ -51,8 +51,10 @@ TR_CLASS(TR_EventDispatcher) { | @@ -51,8 +51,10 @@ TR_CLASS(TR_EventDispatcher) { | ||
51 | TR_Hash handler; | 51 | TR_Hash handler; |
52 | TR_EventHandler default_handler; | 52 | TR_EventHandler default_handler; |
53 | int running; | 53 | int running; |
54 | - int heartbeat; // milliseconds | ||
55 | - int nextbeat; // milliseconds | 54 | + int pollinterval; // milliseconds |
55 | + int nextpoll; // milliseconds | ||
56 | + int heartbeat; // milliseconds | ||
57 | + int nextbeat; // milliseconds | ||
56 | TR_EventDispatcherMode mode; | 58 | TR_EventDispatcherMode mode; |
57 | }; | 59 | }; |
58 | TR_INSTANCE_INIT(TR_EventDispatcher); | 60 | TR_INSTANCE_INIT(TR_EventDispatcher); |
@@ -23,6 +23,7 @@ | @@ -23,6 +23,7 @@ | ||
23 | #include <stdint.h> | 23 | #include <stdint.h> |
24 | #include <signal.h> | 24 | #include <signal.h> |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | +#include <time.h> | ||
26 | 27 | ||
27 | #include "trbase.h" | 28 | #include "trbase.h" |
28 | #include "trdata.h" | 29 | #include "trdata.h" |
@@ -63,6 +64,8 @@ static | @@ -63,6 +64,8 @@ static | ||
63 | int | 64 | int |
64 | eventDispatcherCtor(void * _this, va_list * params) { | 65 | eventDispatcherCtor(void * _this, va_list * params) { |
65 | TR_EventDispatcher this = _this; | 66 | TR_EventDispatcher this = _this; |
67 | + struct timespec tp; | ||
68 | + int now; // milliseconds | ||
66 | 69 | ||
67 | this->events = TR_new(TR_Queue); | 70 | this->events = TR_new(TR_Queue); |
68 | this->handler = TR_new(TR_Hash); | 71 | this->handler = TR_new(TR_Hash); |
@@ -71,6 +74,12 @@ eventDispatcherCtor(void * _this, va_list * params) { | @@ -71,6 +74,12 @@ eventDispatcherCtor(void * _this, va_list * params) { | ||
71 | this->running = 0; | 74 | this->running = 0; |
72 | this->heartbeat = 0; | 75 | this->heartbeat = 0; |
73 | this->nextbeat = 0; | 76 | this->nextbeat = 0; |
77 | + this->pollinterval = va_arg(*params, int); | ||
78 | + | ||
79 | + clock_gettime(CLOCK_REALTIME, &tp); | ||
80 | + now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; | ||
81 | + | ||
82 | + this->nextpoll = now + this->pollinterval; | ||
74 | 83 | ||
75 | if (! _TR_controlDispatcher) { | 84 | if (! _TR_controlDispatcher) { |
76 | _TR_controlDispatcher = this; | 85 | _TR_controlDispatcher = this; |
@@ -30,6 +30,8 @@ | @@ -30,6 +30,8 @@ | ||
30 | #include "tr/event_subject.h" | 30 | #include "tr/event_subject.h" |
31 | #include "tr/event_dispatcher.h" | 31 | #include "tr/event_dispatcher.h" |
32 | 32 | ||
33 | +int ZERO = 0; | ||
34 | + | ||
33 | void | 35 | void |
34 | TR_eventDispatcherStart(TR_EventDispatcher this) | 36 | TR_eventDispatcherStart(TR_EventDispatcher this) |
35 | { | 37 | { |
@@ -55,18 +57,14 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -55,18 +57,14 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
55 | NULL)); | 57 | NULL)); |
56 | } | 58 | } |
57 | 59 | ||
58 | - if (TR_queueEmpty(this->events)) { | ||
59 | - if (TR_EVD_CLIENT == this->mode) { | ||
60 | - event = TR_eventSubjectEmit( | ||
61 | - (TR_EventSubject)this, | ||
62 | - TR_DISPATCHER_EVENT_USER_WAIT, | ||
63 | - NULL); | ||
64 | - } else { | ||
65 | - event = TR_eventSubjectEmit( | ||
66 | - (TR_EventSubject)this, | ||
67 | - TR_DISPATCHER_EVENT_DATA_WAIT, | ||
68 | - NULL); | ||
69 | - } | 60 | + if (TR_queueEmpty(this->events) || this->nextpoll <= now) { |
61 | + int evtid = TR_EVD_CLIENT == this->mode | ||
62 | + ? TR_DISPATCHER_EVENT_USER_WAIT | ||
63 | + : TR_DISPATCHER_EVENT_DATA_WAIT; | ||
64 | + int * toutptr = TR_queueEmpty(this->events) ? NULL : &ZERO; | ||
65 | + | ||
66 | + this->nextpoll += this->pollinterval; | ||
67 | + event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, toutptr); | ||
70 | } else { | 68 | } else { |
71 | event = TR_queueGet(this->events); | 69 | event = TR_queueGet(this->events); |
72 | } | 70 | } |
@@ -83,7 +81,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -83,7 +81,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
83 | 81 | ||
84 | if (handler_queue && ! TR_queueEmpty(handler_queue)) { | 82 | if (handler_queue && ! TR_queueEmpty(handler_queue)) { |
85 | TR_Queue queue_node = handler_queue->first; | 83 | TR_Queue queue_node = handler_queue->first; |
86 | - TR_EventDone done; | 84 | + TR_EventDone done = TR_EVENT_PENDING; |
87 | 85 | ||
88 | while (queue_node) { | 86 | while (queue_node) { |
89 | TR_EventHandler handler = queue_node->msg; | 87 | TR_EventHandler handler = queue_node->msg; |
Please
register
or
login
to post a comment