Merge remote branch 'github/20_once_fixes'

This commit is contained in:
Nick Mathewson 2010-11-25 23:03:46 -05:00
commit 2e5a175bf3
2 changed files with 15 additions and 8 deletions

15
event.c
View File

@ -134,7 +134,7 @@ static void event_queue_insert(struct event_base *, struct event *, int);
static void event_queue_remove(struct event_base *, struct event *, int);
static int event_haveevents(struct event_base *);
static void event_process_active(struct event_base *);
static int event_process_active(struct event_base *);
static int timeout_next(struct event_base *, struct timeval **);
static void timeout_process(struct event_base *);
@ -1341,19 +1341,19 @@ event_process_deferred_callbacks(struct deferred_cb_queue *queue, int *breakptr)
* priority ones.
*/
static void
static int
event_process_active(struct event_base *base)
{
/* Caller must hold th_base_lock */
struct event_list *activeq = NULL;
int i, c;
int i, c = 0;
for (i = 0; i < base->nactivequeues; ++i) {
if (TAILQ_FIRST(&base->activequeues[i]) != NULL) {
activeq = &base->activequeues[i];
c = event_process_active_single_queue(base, activeq);
if (c < 0)
return;
return -1;
else if (c > 0)
break; /* Processed a real event; do not
* consider lower-priority events */
@ -1363,6 +1363,7 @@ event_process_active(struct event_base *base)
}
event_process_deferred_callbacks(&base->defer_queue,&base->event_break);
return c;
}
/*
@ -1547,8 +1548,10 @@ event_base_loop(struct event_base *base, int flags)
timeout_process(base);
if (N_ACTIVE_CALLBACKS(base)) {
event_process_active(base);
if (!base->event_count_active && (flags & EVLOOP_ONCE))
int n = event_process_active(base);
if ((flags & EVLOOP_ONCE)
&& N_ACTIVE_CALLBACKS(base) == 0
&& n != 0)
done = 1;
} else if (flags & EVLOOP_NONBLOCK)
done = 1;

View File

@ -324,8 +324,12 @@ int event_base_set(struct event_base *, struct event *);
event_loop() flags
*/
/*@{*/
#define EVLOOP_ONCE 0x01 /**< Block at most once. */
#define EVLOOP_NONBLOCK 0x02 /**< Do not block. */
/** Block until we have an active event, then exit once all active events
* have had their callbacks run. */
#define EVLOOP_ONCE 0x01
/** Do not block: see which events are ready now, run the callbacks
* highest-priority ones, then exit. */
#define EVLOOP_NONBLOCK 0x02
/*@}*/
/**