|
|
|
@ -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); |
|
|
|
} else { |
|
|
|
pthread_cond_wait(&(this->events_cond), &(this->events_lock)); |
|
|
|
event = NULL; |
|
|
|
} |
|
|
|
} else { |
|
|
|
event = TR_queueGet(this->events); |
|
|
|
} |
|
|
|
|
|
|
|
pthread_mutex_unlock(&(this->events_lock)); |
|
|
|
|
|
|
|
if (! event) { |
|
|
|
char buffer[17]; |
|
|
|
|
|
|
|
pthread_getname_np(pthread_self(), buffer, 17); |
|
|
|
TR_loggerLog(TR_logger, TR_LOGGER_DEBUG, |
|
|
|
"[%s] - enter cond wait", |
|
|
|
buffer); |
|
|
|
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++; |
|
|
|
} |
|
|
|
|
|
|
|
pthread_mutex_unlock(&(this->events_lock)); |
|
|
|
|
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|