Commit 48a57a14f5e76a7f79c4eb318cd2d2571f3aac82

Authored by Georg Hopp
1 parent 5cd826f9

Revert "more thread syncs."

This reverts commit 5cd826f9.
... ... @@ -52,8 +52,7 @@ TR_CLASS(TR_EventDispatcher) {
52 52 TR_Queue events;
53 53 pthread_mutex_t events_lock;
54 54 pthread_cond_t events_cond;
55   - pthread_t events_poll;
56   - size_t events_handling;
  55 + pthread_t events_wait;
57 56
58 57 TR_Hash handler;
59 58 TR_EventHandler default_handler;
... ...
... ... @@ -24,7 +24,6 @@
24 24 #define __TR_EVENT_HANDLER_H__
25 25
26 26 #include <sys/types.h>
27   -#include <pthread.h>
28 27
29 28 #include "trbase.h"
30 29 #include "trdata.h"
... ... @@ -69,12 +68,6 @@ void TR__eventHandlerClassCleanup(TR_class_ptr);
69 68 sizeof(TR_EventMethod_fptr))); \
70 69 } while(0)
71 70
72   -#define TR_INIT_HANDLER(cname) \
73   - TR_INSTANCE(TR_Tree, cname##EventMethodsTree, NULL, PTHREAD_MUTEX_INITIALIZER); \
74   - TR_INSTANCE(TR_Hash, cname##EventMethods, &(_##cname##EventMethodsTree.data), 0)
75   -
76   -#define TR_HANDLER_CVARS(cname) &(_##cname##EventMethods.data)
77   -
78 71 #endif // __TR_EVENT_HANDLER_H__
79 72
80 73 // vim: set ts=4 sw=4:
... ...
... ... @@ -25,14 +25,12 @@
25 25
26 26 #include <sys/types.h>
27 27 #include <stdint.h>
28   -#include <pthread.h>
29 28
30 29 #include "trbase.h"
31 30
32 31 TR_CLASS(TR_EventSubject) {
33   - int fin;
34   - size_t emitted;
35   - pthread_mutex_t lock;
  32 + int fin;
  33 + size_t emitted;
36 34 };
37 35 TR_INSTANCE_INIT(TR_EventSubject);
38 36 TR_CLASSVARS_DECL(TR_EventSubject) {
... ... @@ -59,16 +57,6 @@ TR_CLASSVARS_DECL(TR_EventSubject) {
59 57 intptr_t TR__eventSubjectId(TR_class_ptr, size_t);
60 58 TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *);
61 59
62   -static
63   -inline
64   -void
65   -TR_eventSubjectAbsorb(TR_EventSubject this)
66   -{
67   - pthread_mutex_lock(&this->lock);
68   - this->emitted = this->emitted == 0 ? 0 : this->emitted - 1;
69   - pthread_mutex_unlock(&this->lock);
70   -}
71   -
72 60 #define TR_eventSubjectFinalize(es) ((es)->fin = TRUE)
73 61
74 62 #endif // __TR_EVENT_SUBJECT_H__
... ...
... ... @@ -29,9 +29,8 @@
29 29 #include "event_dispatcher.h"
30 30
31 31 TR_CLASS(TR_EventThread) {
32   - TR_EventDispatcher dispatcher;
33   - pthread_t handle;
34   - char * name;
  32 + TR_EventDispatcher dispatcher;
  33 + pthread_t handle;
35 34 };
36 35 TR_INSTANCE_INIT(TR_EventThread);
37 36 TR_CLASSVARS_DECL(TR_EventThread) {};
... ...
... ... @@ -41,13 +41,13 @@ eventCtor(void * _this, va_list * params)
41 41 return 0;
42 42 }
43 43
44   -static
45   -void
46   -eventDtor(void * _this)
  44 +static void eventDtor(void * _this)
47 45 {
48 46 TR_Event this = _this;
49 47
50   - TR_eventSubjectAbsorb(this->subject);
  48 + this->subject->emitted =
  49 + this->subject->emitted == 0
  50 + ? 0 : this->subject->emitted - 1;
51 51
52 52 if (0 == this->subject->emitted && this->subject->fin) {
53 53 TR_delete(this->subject);
... ...
... ... @@ -57,7 +57,6 @@ init_signals(void)
57 57 signal(SIGABRT, terminate);
58 58 signal(SIGALRM, SIG_IGN);
59 59 signal(SIGURG, SIG_IGN);
60   - signal(SIGUSR1, SIG_IGN);
61 60
62 61 signal(SIGPIPE, SIG_IGN);
63 62 }
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#define _GNU_SOURCE
24   -
25 23 #include "trbase.h"
26 24 #include "trdata.h"
27 25 #include "trhash.h"
... ... @@ -51,39 +49,28 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
51 49 (TR_EventSubject)this,
52 50 TR_DISPATCHER_EVENT_HEARTBEAT,
53 51 NULL);
54   - } else {
55   - event = TR_queueGet(this->events);
56   -
57   - if (! (event || this->events_poll || this->events_handling)) {
  52 + } else if (TR_queueEmpty(this->events)) {
  53 + if (! this->events_wait) {
58 54 int evtid = TR_EVD_CLIENT == this->mode
59 55 ? TR_DISPATCHER_EVENT_USER_WAIT
60 56 : TR_DISPATCHER_EVENT_DATA_WAIT;
61 57
62   - this->events_poll = pthread_self();
  58 + this->events_wait = pthread_self();
63 59 event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, NULL);
  60 + } else {
  61 + pthread_cond_wait(&(this->events_cond), &(this->events_lock));
  62 + event = NULL;
64 63 }
  64 + } else {
  65 + event = TR_queueGet(this->events);
65 66 }
66 67
  68 + pthread_mutex_unlock(&(this->events_lock));
  69 +
67 70 if (! event) {
68   - char buffer[17];
69   -
70   - pthread_getname_np(pthread_self(), buffer, 17);
71   - TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
72   - "[%s] - enter cond wait",
73   - buffer);
74   - pthread_cond_wait(&(this->events_cond), &(this->events_lock));
75   - TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
76   - "[%s] - leave cond wait",
77   - buffer);
78   - event = NULL;
79   - pthread_mutex_unlock(&(this->events_lock));
80 71 continue;
81   - } else {
82   - this->events_handling++;
83 72 }
84 73
85   - pthread_mutex_unlock(&(this->events_lock));
86   -
87 74 handler_queue_hv = TR_hashGetByVal(
88 75 this->handler,
89 76 TR_sdbm(
... ... @@ -117,12 +104,9 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
117 104 TR_delete(event);
118 105 }
119 106
120   - pthread_mutex_lock(&(this->events_lock));
121   - this->events_handling--;
122   - if (pthread_equal(this->events_poll, pthread_self())) {
123   - this->events_poll = FALSE;
  107 + if (pthread_equal(this->events_wait, pthread_self())) {
  108 + this->events_wait = FALSE;
124 109 }
125   - pthread_mutex_unlock(&(this->events_lock));
126 110 }
127 111 }
128 112
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#define _GNU_SOURCE
24   -
25 23 #include <stdio.h>
26 24
27 25 #include "trbase.h"
... ... @@ -34,7 +32,7 @@
34 32 TR_EventDone
35 33 TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event)
36 34 {
37   - char buffer[17];
  35 + TR_EventDone retval;
38 36 TR_EventMethod_fptr event_func = NULL;
39 37 TR_HashValue handle_func_hv = TR_hashGetByVal(
40 38 TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods,
... ... @@ -46,17 +44,17 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event)
46 44
47 45 event_func = *(TR_EventMethod_fptr *)handle_func_hv->value;
48 46
49   - pthread_getname_np(pthread_self(), buffer, 17);
  47 + retval = event_func(this, event);
50 48
51 49 TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
52   - "[%s] - HANDLE(%zd): %s event on %p with no. %d",
53   - buffer,
  50 + "[%ld] - HANDLE(%zd): %s event on %p with no. %d",
  51 + pthread_self(),
54 52 event->subject->emitted,
55 53 TR_getEventString(event),
56 54 event->subject,
57 55 event->serial);
58 56
59   - return event_func(this, event);
  57 + return retval;
60 58 }
61 59
62 60 // vim: set ts=4 sw=4:
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#define _GNU_SOURCE
24   -
25 23 #include <stdio.h>
26 24 #include <pthread.h>
27 25
... ... @@ -34,15 +32,12 @@ int
34 32 TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event)
35 33 {
36 34 if (event) {
37   - int i;
38   - char buffer[17];
39   -
40   - pthread_getname_np(pthread_self(), buffer, 17);
  35 + int i;
41 36
42 37 for (i=0; i<this->ndispatcher; i++) {
43 38 TR_loggerLog(TR_logger, TR_LOGGER_DEBUG,
44   - "[%s] - ISSUE(%zd): %s event on %p with no. %d",
45   - buffer,
  39 + "[%ld] - ISSUE(%zd): %s event on %p with no. %d",
  40 + pthread_self(),
46 41 event->subject->emitted,
47 42 TR_getEventString(event),
48 43 event->subject,
... ...
... ... @@ -27,21 +27,8 @@
27 27 #include "tr/logger.h"
28 28 #include "trbase.h"
29 29
30   -static
31   -int
32   -eventSubjectCtor(void * _this, va_list * params)
33   -{
34   - pthread_mutex_init(&((TR_EventSubject)_this)->lock, NULL);
35   -
36   - return 0;
37   -}
38   -
39   -static
40   -void
41   -eventSubjectDtor(void * _this)
42   -{
43   - pthread_mutex_destroy(&((TR_EventSubject)_this)->lock);
44   -}
  30 +static int eventSubjectCtor(void * _this, va_list * params) { return 0; }
  31 +static void eventSubjectDtor(void * _this) {}
45 32
46 33 TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL);
47 34 TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = {
... ...
... ... @@ -22,7 +22,6 @@
22 22
23 23 #include <stdio.h>
24 24 #include <stdint.h>
25   -#include <pthread.h>
26 25
27 26 #include "tr/event.h"
28 27 #include "tr/event_subject.h"
... ... @@ -38,9 +37,7 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data)
38 37 if (id && ! this->fin) {
39 38 event = TR_new(TR_Event, id, this);
40 39 TR_eventSetData(event, data);
41   - pthread_mutex_lock(&this->lock);
42 40 this->emitted++;
43   - pthread_mutex_unlock(&this->lock);
44 41 }
45 42
46 43 return event;
... ...
... ... @@ -31,13 +31,9 @@ static
31 31 int
32 32 eventThreadCtor(void * _this, va_list * params)
33 33 {
34   - TR_EventThread this = _this;
35   - char * name;
  34 + TR_EventThread this = _this;
36 35
37 36 this->dispatcher = va_arg(*params, TR_EventDispatcher);
38   - name = va_arg(*params, char *);
39   -
40   - if (name) this->name = TR_strdup(name);
41 37
42 38 return 0;
43 39 }
... ... @@ -52,8 +48,6 @@ eventThreadDtor(void * _this)
52 48 pthread_cancel(this->handle);
53 49 pthread_join(this->handle, NULL);
54 50 }
55   -
56   - TR_MEM_FREE(this->name);
57 51 }
58 52
59 53 TR_INIT_IFACE(TR_Class, eventThreadCtor, eventThreadDtor, NULL);
... ...
... ... @@ -20,8 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#define _GNU_SOURCE
24   -
25 23 #include <pthread.h>
26 24
27 25 #include "trbase.h"
... ... @@ -34,7 +32,6 @@ void *
34 32 TR_eventStreadRun(void * message)
35 33 {
36 34 TR_EventThread this = message;
37   - if (this->name) pthread_setname_np(pthread_self(), this->name);
38 35 TR_eventDispatcherStart(this->dispatcher);
39 36 return NULL;
40 37 }
... ...
Please register or login to post a comment