Browse Source

Revert "more thread syncs."

This reverts commit 5cd826f91a.
1.0.0
Georg Hopp 11 years ago
parent
commit
bce8f9eaa8
  1. 3
      include/tr/event_dispatcher.h
  2. 7
      include/tr/event_handler.h
  3. 12
      include/tr/event_subject.h
  4. 1
      include/tr/event_thread.h
  5. 8
      src/event.c
  6. 1
      src/event_dispatcher.c
  7. 40
      src/event_dispatcher_start.c
  8. 12
      src/event_handler_handle_event.c
  9. 9
      src/event_handler_issue_event.c
  10. 17
      src/event_subject.c
  11. 3
      src/event_subject_emit.c
  12. 6
      src/event_thread.c
  13. 3
      src/event_thread_start.c

3
include/tr/event_dispatcher.h

@ -52,8 +52,7 @@ TR_CLASS(TR_EventDispatcher) {
TR_Queue events;
pthread_mutex_t events_lock;
pthread_cond_t events_cond;
pthread_t events_poll;
size_t events_handling;
pthread_t events_wait;
TR_Hash handler;
TR_EventHandler default_handler;

7
include/tr/event_handler.h

@ -24,7 +24,6 @@
#define __TR_EVENT_HANDLER_H__
#include <sys/types.h>
#include <pthread.h>
#include "trbase.h"
#include "trdata.h"
@ -69,12 +68,6 @@ void TR__eventHandlerClassCleanup(TR_class_ptr);
sizeof(TR_EventMethod_fptr))); \
} while(0)
#define TR_INIT_HANDLER(cname) \
TR_INSTANCE(TR_Tree, cname##EventMethodsTree, NULL, PTHREAD_MUTEX_INITIALIZER); \
TR_INSTANCE(TR_Hash, cname##EventMethods, &(_##cname##EventMethodsTree.data), 0)
#define TR_HANDLER_CVARS(cname) &(_##cname##EventMethods.data)
#endif // __TR_EVENT_HANDLER_H__
// vim: set ts=4 sw=4:

12
include/tr/event_subject.h

@ -25,14 +25,12 @@
#include <sys/types.h>
#include <stdint.h>
#include <pthread.h>
#include "trbase.h"
TR_CLASS(TR_EventSubject) {
int fin;
size_t emitted;
pthread_mutex_t lock;
};
TR_INSTANCE_INIT(TR_EventSubject);
TR_CLASSVARS_DECL(TR_EventSubject) {
@ -59,16 +57,6 @@ TR_CLASSVARS_DECL(TR_EventSubject) {
intptr_t TR__eventSubjectId(TR_class_ptr, size_t);
TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *);
static
inline
void
TR_eventSubjectAbsorb(TR_EventSubject this)
{
pthread_mutex_lock(&this->lock);
this->emitted = this->emitted == 0 ? 0 : this->emitted - 1;
pthread_mutex_unlock(&this->lock);
}
#define TR_eventSubjectFinalize(es) ((es)->fin = TRUE)
#endif // __TR_EVENT_SUBJECT_H__

1
include/tr/event_thread.h

@ -31,7 +31,6 @@
TR_CLASS(TR_EventThread) {
TR_EventDispatcher dispatcher;
pthread_t handle;
char * name;
};
TR_INSTANCE_INIT(TR_EventThread);
TR_CLASSVARS_DECL(TR_EventThread) {};

8
src/event.c

@ -41,13 +41,13 @@ eventCtor(void * _this, va_list * params)
return 0;
}
static
void
eventDtor(void * _this)
static void eventDtor(void * _this)
{
TR_Event this = _this;
TR_eventSubjectAbsorb(this->subject);
this->subject->emitted =
this->subject->emitted == 0
? 0 : this->subject->emitted - 1;
if (0 == this->subject->emitted && this->subject->fin) {
TR_delete(this->subject);

1
src/event_dispatcher.c

@ -57,7 +57,6 @@ init_signals(void)
signal(SIGABRT, terminate);
signal(SIGALRM, SIG_IGN);
signal(SIGURG, SIG_IGN);
signal(SIGUSR1, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
}

40
src/event_dispatcher_start.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include "trbase.h"
#include "trdata.h"
#include "trhash.h"
@ -51,39 +49,28 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
(TR_EventSubject)this,
TR_DISPATCHER_EVENT_HEARTBEAT,
NULL);
} else {
event = TR_queueGet(this->events);
if (! (event || this->events_poll || this->events_handling)) {
} else if (TR_queueEmpty(this->events)) {
if (! this->events_wait) {
int evtid = TR_EVD_CLIENT == this->mode
? TR_DISPATCHER_EVENT_USER_WAIT
: TR_DISPATCHER_EVENT_DATA_WAIT;
this->events_poll = pthread_self();
this->events_wait = pthread_self();
event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, NULL);
}
}
if (! event) {
char buffer[17];
pthread_getname_np(pthread_self(), buffer, 17);
TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
"[%s] - enter cond wait",
buffer);
} else {
pthread_cond_wait(&(this->events_cond), &(this->events_lock));
TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
"[%s] - leave cond wait",
buffer);
event = NULL;
pthread_mutex_unlock(&(this->events_lock));
continue;
}
} else {
this->events_handling++;
event = TR_queueGet(this->events);
}
pthread_mutex_unlock(&(this->events_lock));
if (! event) {
continue;
}
handler_queue_hv = TR_hashGetByVal(
this->handler,
TR_sdbm(
@ -117,12 +104,9 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
TR_delete(event);
}
pthread_mutex_lock(&(this->events_lock));
this->events_handling--;
if (pthread_equal(this->events_poll, pthread_self())) {
this->events_poll = FALSE;
if (pthread_equal(this->events_wait, pthread_self())) {
this->events_wait = FALSE;
}
pthread_mutex_unlock(&(this->events_lock));
}
}

12
src/event_handler_handle_event.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include "trbase.h"
@ -34,7 +32,7 @@
TR_EventDone
TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event)
{
char buffer[17];
TR_EventDone retval;
TR_EventMethod_fptr event_func = NULL;
TR_HashValue handle_func_hv = TR_hashGetByVal(
TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods,
@ -46,17 +44,17 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event)
event_func = *(TR_EventMethod_fptr *)handle_func_hv->value;
pthread_getname_np(pthread_self(), buffer, 17);
retval = event_func(this, event);
TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
"[%s] - HANDLE(%zd): %s event on %p with no. %d",
buffer,
"[%ld] - HANDLE(%zd): %s event on %p with no. %d",
pthread_self(),
event->subject->emitted,
TR_getEventString(event),
event->subject,
event->serial);
return event_func(this, event);
return retval;
}
// vim: set ts=4 sw=4:

9
src/event_handler_issue_event.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
@ -35,14 +33,11 @@ TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event)
{
if (event) {
int i;
char buffer[17];
pthread_getname_np(pthread_self(), buffer, 17);
for (i=0; i<this->ndispatcher; i++) {
TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
"[%s] - ISSUE(%zd): %s event on %p with no. %d",
buffer,
"[%ld] - ISSUE(%zd): %s event on %p with no. %d",
pthread_self(),
event->subject->emitted,
TR_getEventString(event),
event->subject,

17
src/event_subject.c

@ -27,21 +27,8 @@
#include "tr/logger.h"
#include "trbase.h"
static
int
eventSubjectCtor(void * _this, va_list * params)
{
pthread_mutex_init(&((TR_EventSubject)_this)->lock, NULL);
return 0;
}
static
void
eventSubjectDtor(void * _this)
{
pthread_mutex_destroy(&((TR_EventSubject)_this)->lock);
}
static int eventSubjectCtor(void * _this, va_list * params) { return 0; }
static void eventSubjectDtor(void * _this) {}
TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL);
TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = {

3
src/event_subject_emit.c

@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include "tr/event.h"
#include "tr/event_subject.h"
@ -38,9 +37,7 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data)
if (id && ! this->fin) {
event = TR_new(TR_Event, id, this);
TR_eventSetData(event, data);
pthread_mutex_lock(&this->lock);
this->emitted++;
pthread_mutex_unlock(&this->lock);
}
return event;

6
src/event_thread.c

@ -32,12 +32,8 @@ int
eventThreadCtor(void * _this, va_list * params)
{
TR_EventThread this = _this;
char * name;
this->dispatcher = va_arg(*params, TR_EventDispatcher);
name = va_arg(*params, char *);
if (name) this->name = TR_strdup(name);
return 0;
}
@ -52,8 +48,6 @@ eventThreadDtor(void * _this)
pthread_cancel(this->handle);
pthread_join(this->handle, NULL);
}
TR_MEM_FREE(this->name);
}
TR_INIT_IFACE(TR_Class, eventThreadCtor, eventThreadDtor, NULL);

3
src/event_thread_start.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include "trbase.h"
@ -34,7 +32,6 @@ void *
TR_eventStreadRun(void * message)
{
TR_EventThread this = message;
if (this->name) pthread_setname_np(pthread_self(), this->name);
TR_eventDispatcherStart(this->dispatcher);
return NULL;
}

Loading…
Cancel
Save