@ -29,6 +29,7 @@
#include "trbase.h"
TR_CLASS(TR_EventSubject) {
int fin;
size_t emitted;
};
TR_INSTANCE_INIT(TR_EventSubject);
@ -55,6 +56,8 @@ TR_CLASSVARS_DECL(TR_EventSubject) {
intptr_t TR__eventSubjectId(TR_class_ptr, size_t);
TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *);
#define TR_eventSubjectFinalize(es) ((es)->fin = TRUE)
#endif // __TR_EVENT_SUBJECT_H__
// vim: set ts=4 sw=4:
@ -45,7 +45,13 @@ static void eventDtor(void * _this)
{
TR_Event this = _this;
this->subject->emitted--;
this->subject->emitted =
this->subject->emitted == 0
? 0 : this->subject->emitted - 1;
if (0 == this->subject->emitted && this->subject->fin) {
TR_delete(this->subject);
}
TR_INIT_IFACE(TR_Class, eventCtor, eventDtor, NULL);
@ -49,15 +49,11 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
if (this->nextbeat && this->nextbeat <= now) {
this->nextbeat += this->heartbeat;
TR_eventDispatcherEnqueueEvent(
this,
TR_eventSubjectEmit(
(TR_EventSubject)this,
TR_DISPATCHER_EVENT_HEARTBEAT,
NULL));
if (TR_queueEmpty(this->events) || this->nextpoll <= now) {
event = TR_eventSubjectEmit(
NULL);
} else if (TR_queueEmpty(this->events) || this->nextpoll <= now) {
int evtid = TR_EVD_CLIENT == this->mode
? TR_DISPATCHER_EVENT_USER_WAIT
: TR_DISPATCHER_EVENT_DATA_WAIT;
@ -30,8 +30,10 @@ TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event)
int i;
for (i=0; i<this->ndispatcher; i++) {
TR_eventDispatcherEnqueueEvent(this->dispatcher[i], event);
if (event) {
@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdint.h>
#include "tr/event.h"
@ -33,13 +34,12 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data)
intptr_t id = TR_eventSubjectGetId(this, idx);
TR_Event event = NULL;
if (id) {
if (id && ! this->fin) {
event = TR_new(TR_Event, id, this);
TR_eventSetData(event, data);
this->emitted++;
return event;