Commit 48a57a14f5e76a7f79c4eb318cd2d2571f3aac82
1 parent
5cd826f9
Revert "more thread syncs."
This reverts commit 5cd826f9.
Showing
13 changed files
with
32 additions
and
102 deletions
@@ -52,8 +52,7 @@ TR_CLASS(TR_EventDispatcher) { | @@ -52,8 +52,7 @@ TR_CLASS(TR_EventDispatcher) { | ||
52 | TR_Queue events; | 52 | TR_Queue events; |
53 | pthread_mutex_t events_lock; | 53 | pthread_mutex_t events_lock; |
54 | pthread_cond_t events_cond; | 54 | pthread_cond_t events_cond; |
55 | - pthread_t events_poll; | ||
56 | - size_t events_handling; | 55 | + pthread_t events_wait; |
57 | 56 | ||
58 | TR_Hash handler; | 57 | TR_Hash handler; |
59 | TR_EventHandler default_handler; | 58 | TR_EventHandler default_handler; |
@@ -24,7 +24,6 @@ | @@ -24,7 +24,6 @@ | ||
24 | #define __TR_EVENT_HANDLER_H__ | 24 | #define __TR_EVENT_HANDLER_H__ |
25 | 25 | ||
26 | #include <sys/types.h> | 26 | #include <sys/types.h> |
27 | -#include <pthread.h> | ||
28 | 27 | ||
29 | #include "trbase.h" | 28 | #include "trbase.h" |
30 | #include "trdata.h" | 29 | #include "trdata.h" |
@@ -69,12 +68,6 @@ void TR__eventHandlerClassCleanup(TR_class_ptr); | @@ -69,12 +68,6 @@ void TR__eventHandlerClassCleanup(TR_class_ptr); | ||
69 | sizeof(TR_EventMethod_fptr))); \ | 68 | sizeof(TR_EventMethod_fptr))); \ |
70 | } while(0) | 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 | #endif // __TR_EVENT_HANDLER_H__ | 71 | #endif // __TR_EVENT_HANDLER_H__ |
79 | 72 | ||
80 | // vim: set ts=4 sw=4: | 73 | // vim: set ts=4 sw=4: |
@@ -25,14 +25,12 @@ | @@ -25,14 +25,12 @@ | ||
25 | 25 | ||
26 | #include <sys/types.h> | 26 | #include <sys/types.h> |
27 | #include <stdint.h> | 27 | #include <stdint.h> |
28 | -#include <pthread.h> | ||
29 | 28 | ||
30 | #include "trbase.h" | 29 | #include "trbase.h" |
31 | 30 | ||
32 | TR_CLASS(TR_EventSubject) { | 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 | TR_INSTANCE_INIT(TR_EventSubject); | 35 | TR_INSTANCE_INIT(TR_EventSubject); |
38 | TR_CLASSVARS_DECL(TR_EventSubject) { | 36 | TR_CLASSVARS_DECL(TR_EventSubject) { |
@@ -59,16 +57,6 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | @@ -59,16 +57,6 @@ TR_CLASSVARS_DECL(TR_EventSubject) { | ||
59 | intptr_t TR__eventSubjectId(TR_class_ptr, size_t); | 57 | intptr_t TR__eventSubjectId(TR_class_ptr, size_t); |
60 | TR_Event TR_eventSubjectEmit(TR_EventSubject, int, void *); | 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 | #define TR_eventSubjectFinalize(es) ((es)->fin = TRUE) | 60 | #define TR_eventSubjectFinalize(es) ((es)->fin = TRUE) |
73 | 61 | ||
74 | #endif // __TR_EVENT_SUBJECT_H__ | 62 | #endif // __TR_EVENT_SUBJECT_H__ |
@@ -29,9 +29,8 @@ | @@ -29,9 +29,8 @@ | ||
29 | #include "event_dispatcher.h" | 29 | #include "event_dispatcher.h" |
30 | 30 | ||
31 | TR_CLASS(TR_EventThread) { | 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 | TR_INSTANCE_INIT(TR_EventThread); | 35 | TR_INSTANCE_INIT(TR_EventThread); |
37 | TR_CLASSVARS_DECL(TR_EventThread) {}; | 36 | TR_CLASSVARS_DECL(TR_EventThread) {}; |
@@ -41,13 +41,13 @@ eventCtor(void * _this, va_list * params) | @@ -41,13 +41,13 @@ eventCtor(void * _this, va_list * params) | ||
41 | return 0; | 41 | return 0; |
42 | } | 42 | } |
43 | 43 | ||
44 | -static | ||
45 | -void | ||
46 | -eventDtor(void * _this) | 44 | +static void eventDtor(void * _this) |
47 | { | 45 | { |
48 | TR_Event this = _this; | 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 | if (0 == this->subject->emitted && this->subject->fin) { | 52 | if (0 == this->subject->emitted && this->subject->fin) { |
53 | TR_delete(this->subject); | 53 | TR_delete(this->subject); |
@@ -57,7 +57,6 @@ init_signals(void) | @@ -57,7 +57,6 @@ init_signals(void) | ||
57 | signal(SIGABRT, terminate); | 57 | signal(SIGABRT, terminate); |
58 | signal(SIGALRM, SIG_IGN); | 58 | signal(SIGALRM, SIG_IGN); |
59 | signal(SIGURG, SIG_IGN); | 59 | signal(SIGURG, SIG_IGN); |
60 | - signal(SIGUSR1, SIG_IGN); | ||
61 | 60 | ||
62 | signal(SIGPIPE, SIG_IGN); | 61 | signal(SIGPIPE, SIG_IGN); |
63 | } | 62 | } |
@@ -20,8 +20,6 @@ | @@ -20,8 +20,6 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#define _GNU_SOURCE | ||
24 | - | ||
25 | #include "trbase.h" | 23 | #include "trbase.h" |
26 | #include "trdata.h" | 24 | #include "trdata.h" |
27 | #include "trhash.h" | 25 | #include "trhash.h" |
@@ -51,39 +49,28 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -51,39 +49,28 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
51 | (TR_EventSubject)this, | 49 | (TR_EventSubject)this, |
52 | TR_DISPATCHER_EVENT_HEARTBEAT, | 50 | TR_DISPATCHER_EVENT_HEARTBEAT, |
53 | NULL); | 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 | int evtid = TR_EVD_CLIENT == this->mode | 54 | int evtid = TR_EVD_CLIENT == this->mode |
59 | ? TR_DISPATCHER_EVENT_USER_WAIT | 55 | ? TR_DISPATCHER_EVENT_USER_WAIT |
60 | : TR_DISPATCHER_EVENT_DATA_WAIT; | 56 | : TR_DISPATCHER_EVENT_DATA_WAIT; |
61 | 57 | ||
62 | - this->events_poll = pthread_self(); | 58 | + this->events_wait = pthread_self(); |
63 | event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, NULL); | 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 | if (! event) { | 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 | continue; | 71 | continue; |
81 | - } else { | ||
82 | - this->events_handling++; | ||
83 | } | 72 | } |
84 | 73 | ||
85 | - pthread_mutex_unlock(&(this->events_lock)); | ||
86 | - | ||
87 | handler_queue_hv = TR_hashGetByVal( | 74 | handler_queue_hv = TR_hashGetByVal( |
88 | this->handler, | 75 | this->handler, |
89 | TR_sdbm( | 76 | TR_sdbm( |
@@ -117,12 +104,9 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | @@ -117,12 +104,9 @@ TR_eventDispatcherStart(TR_EventDispatcher this) | ||
117 | TR_delete(event); | 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,8 +20,6 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#define _GNU_SOURCE | ||
24 | - | ||
25 | #include <stdio.h> | 23 | #include <stdio.h> |
26 | 24 | ||
27 | #include "trbase.h" | 25 | #include "trbase.h" |
@@ -34,7 +32,7 @@ | @@ -34,7 +32,7 @@ | ||
34 | TR_EventDone | 32 | TR_EventDone |
35 | TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) | 33 | TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) |
36 | { | 34 | { |
37 | - char buffer[17]; | 35 | + TR_EventDone retval; |
38 | TR_EventMethod_fptr event_func = NULL; | 36 | TR_EventMethod_fptr event_func = NULL; |
39 | TR_HashValue handle_func_hv = TR_hashGetByVal( | 37 | TR_HashValue handle_func_hv = TR_hashGetByVal( |
40 | TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods, | 38 | TR_CLASSVARS(TR_EventHandler, TR_GET_CLASS(this))->event_methods, |
@@ -46,17 +44,17 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) | @@ -46,17 +44,17 @@ TR_eventHandlerHandleEvent(TR_EventHandler this, TR_Event event) | ||
46 | 44 | ||
47 | event_func = *(TR_EventMethod_fptr *)handle_func_hv->value; | 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 | TR_loggerLog(TR_logger, TR_LOGGER_DEBUG, | 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 | event->subject->emitted, | 52 | event->subject->emitted, |
55 | TR_getEventString(event), | 53 | TR_getEventString(event), |
56 | event->subject, | 54 | event->subject, |
57 | event->serial); | 55 | event->serial); |
58 | 56 | ||
59 | - return event_func(this, event); | 57 | + return retval; |
60 | } | 58 | } |
61 | 59 | ||
62 | // vim: set ts=4 sw=4: | 60 | // vim: set ts=4 sw=4: |
@@ -20,8 +20,6 @@ | @@ -20,8 +20,6 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#define _GNU_SOURCE | ||
24 | - | ||
25 | #include <stdio.h> | 23 | #include <stdio.h> |
26 | #include <pthread.h> | 24 | #include <pthread.h> |
27 | 25 | ||
@@ -34,15 +32,12 @@ int | @@ -34,15 +32,12 @@ int | ||
34 | TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event) | 32 | TR_eventHandlerIssueEvent(TR_EventHandler this, TR_Event event) |
35 | { | 33 | { |
36 | if (event) { | 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 | for (i=0; i<this->ndispatcher; i++) { | 37 | for (i=0; i<this->ndispatcher; i++) { |
43 | TR_loggerLog(TR_logger, TR_LOGGER_DEBUG, | 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 | event->subject->emitted, | 41 | event->subject->emitted, |
47 | TR_getEventString(event), | 42 | TR_getEventString(event), |
48 | event->subject, | 43 | event->subject, |
@@ -27,21 +27,8 @@ | @@ -27,21 +27,8 @@ | ||
27 | #include "tr/logger.h" | 27 | #include "tr/logger.h" |
28 | #include "trbase.h" | 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 | TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL); | 33 | TR_INIT_IFACE(TR_Class, eventSubjectCtor, eventSubjectDtor, NULL); |
47 | TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = { | 34 | TR_CREATE_CLASS(TR_EventSubject, NULL, NULL, TR_IF(TR_Class)) = { |
@@ -22,7 +22,6 @@ | @@ -22,7 +22,6 @@ | ||
22 | 22 | ||
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <stdint.h> | 24 | #include <stdint.h> |
25 | -#include <pthread.h> | ||
26 | 25 | ||
27 | #include "tr/event.h" | 26 | #include "tr/event.h" |
28 | #include "tr/event_subject.h" | 27 | #include "tr/event_subject.h" |
@@ -38,9 +37,7 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data) | @@ -38,9 +37,7 @@ TR_eventSubjectEmit(TR_EventSubject this, int idx, void * data) | ||
38 | if (id && ! this->fin) { | 37 | if (id && ! this->fin) { |
39 | event = TR_new(TR_Event, id, this); | 38 | event = TR_new(TR_Event, id, this); |
40 | TR_eventSetData(event, data); | 39 | TR_eventSetData(event, data); |
41 | - pthread_mutex_lock(&this->lock); | ||
42 | this->emitted++; | 40 | this->emitted++; |
43 | - pthread_mutex_unlock(&this->lock); | ||
44 | } | 41 | } |
45 | 42 | ||
46 | return event; | 43 | return event; |
@@ -31,13 +31,9 @@ static | @@ -31,13 +31,9 @@ static | ||
31 | int | 31 | int |
32 | eventThreadCtor(void * _this, va_list * params) | 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 | this->dispatcher = va_arg(*params, TR_EventDispatcher); | 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 | return 0; | 38 | return 0; |
43 | } | 39 | } |
@@ -52,8 +48,6 @@ eventThreadDtor(void * _this) | @@ -52,8 +48,6 @@ eventThreadDtor(void * _this) | ||
52 | pthread_cancel(this->handle); | 48 | pthread_cancel(this->handle); |
53 | pthread_join(this->handle, NULL); | 49 | pthread_join(this->handle, NULL); |
54 | } | 50 | } |
55 | - | ||
56 | - TR_MEM_FREE(this->name); | ||
57 | } | 51 | } |
58 | 52 | ||
59 | TR_INIT_IFACE(TR_Class, eventThreadCtor, eventThreadDtor, NULL); | 53 | TR_INIT_IFACE(TR_Class, eventThreadCtor, eventThreadDtor, NULL); |
@@ -20,8 +20,6 @@ | @@ -20,8 +20,6 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#define _GNU_SOURCE | ||
24 | - | ||
25 | #include <pthread.h> | 23 | #include <pthread.h> |
26 | 24 | ||
27 | #include "trbase.h" | 25 | #include "trbase.h" |
@@ -34,7 +32,6 @@ void * | @@ -34,7 +32,6 @@ void * | ||
34 | TR_eventStreadRun(void * message) | 32 | TR_eventStreadRun(void * message) |
35 | { | 33 | { |
36 | TR_EventThread this = message; | 34 | TR_EventThread this = message; |
37 | - if (this->name) pthread_setname_np(pthread_self(), this->name); | ||
38 | TR_eventDispatcherStart(this->dispatcher); | 35 | TR_eventDispatcherStart(this->dispatcher); |
39 | return NULL; | 36 | return NULL; |
40 | } | 37 | } |
Please
register
or
login
to post a comment