ethereum/event/BREvent.c
/**
 * Stop the handler.  This will clear all pending events.  If there is a periodic alarm, it will
 * be removed from the alarmClock.
 *
 * @note There is a tiny race here, I think.  Before this function returns and after the queue
 * has been cleared, another event can be added.  This is prevented by stopping the threads that
 * submit to this queue before stopping this queue's thread.  Or prior to a subsequent start,
 * clear this handler (But, `eventHandlerStart()` does not clear the thread on start.)
 *
 * @param handler
 */
Stop the handler.  This will clear all pending events.  If there is a periodic alarm, it will
be removed from the alarmClock.

@note There is a tiny race here, I think.  Before this function returns and after the queue
has been cleared, another event can be added.  This is prevented by stopping the threads that
submit to this queue before stopping this queue's thread.  Or prior to a subsequent start,
clear this handler (But, `eventHandlerStart()` does not clear the thread on start.)

@param handler
Stop the handler . This will clear all pending events . If there is a periodic alarm it will be removed from the alarmClock . @note There is a tiny race here I think . Before this function returns and after the queue has been cleared another event can be added . This is prevented by stopping the threads that submit to this queue before stopping this queue ' s thread . Or prior to a subsequent start clear this handler ( But ` eventHandlerStart () ` does not clear the thread on start . ) @param handler
extern void
eventHandlerStop (BREventHandler handler) {
    pthread_mutex_lock(&handler->lock);
    if (PTHREAD_NULL != handler->thread) {
        if (ALARM_ID_NONE != handler->timeoutAlarmId) {
            alarmClockRemAlarm (alarmClock, handler->timeoutAlarmId);
            handler->timeoutAlarmId = ALARM_ID_NONE;
        }
        eventQueueDequeueWaitAbort (handler->queue);
        pthread_join (handler->thread, NULL);
        handler->thread = PTHREAD_NULL;
        eventQueueDequeueWaitAbortReset (handler->queue);
        eventHandlerClear (handler);
    }
    pthread_mutex_unlock(&handler->lock);
}
extern void eventHandlerStop ( BREventHandler handler ) { pthread_mutex_lock ( & handler -> lock ) ; if ( PTHREAD_NULL != handler -> thread ) { if ( ALARM_ID_NONE != handler -> timeoutAlarmId ) { alarmClockRemAlarm ( alarmClock , handler -> timeoutAlarmId ) ; handler -> timeoutAlarmId = ALARM_ID_NONE ; } eventQueueDequeueWaitAbort ( handler -> queue ) ; pthread_join ( handler -> thread , NULL ) ; handler -> thread = PTHREAD_NULL ; eventQueueDequeueWaitAbortReset ( handler -> queue ) ; eventHandlerClear ( handler ) ; } pthread_mutex_unlock ( & handler -> lock ) ; }
Stop the handler.
Stop the handler .
// Remove a timeout alarm, if it exists. // Quit the thread by aborting the queue wait. // Wait for the thread. // A mini-race here? // TODO: Empty the queue completely?  Or not?