mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-17 16:29:28 -04:00
Merge remote-tracking branch 'github/linked_list'
Conflicts: include/event2/event_struct.h
This commit is contained in:
commit
5683e2b1a8
26
buffer.c
26
buffer.c
@ -358,7 +358,7 @@ evbuffer_new(void)
|
||||
if (buffer == NULL)
|
||||
return (NULL);
|
||||
|
||||
TAILQ_INIT(&buffer->callbacks);
|
||||
LIST_INIT(&buffer->callbacks);
|
||||
buffer->refcnt = 1;
|
||||
buffer->last_with_datap = &buffer->first;
|
||||
|
||||
@ -467,7 +467,7 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred)
|
||||
|
||||
ASSERT_EVBUFFER_LOCKED(buffer);
|
||||
|
||||
if (TAILQ_EMPTY(&buffer->callbacks)) {
|
||||
if (LIST_EMPTY(&buffer->callbacks)) {
|
||||
buffer->n_add_for_cb = buffer->n_del_for_cb = 0;
|
||||
return;
|
||||
}
|
||||
@ -482,12 +482,12 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred)
|
||||
buffer->n_add_for_cb = 0;
|
||||
buffer->n_del_for_cb = 0;
|
||||
}
|
||||
for (cbent = TAILQ_FIRST(&buffer->callbacks);
|
||||
cbent != TAILQ_END(&buffer->callbacks);
|
||||
for (cbent = LIST_FIRST(&buffer->callbacks);
|
||||
cbent != LIST_END(&buffer->callbacks);
|
||||
cbent = next) {
|
||||
/* Get the 'next' pointer now in case this callback decides
|
||||
* to remove itself or something. */
|
||||
next = TAILQ_NEXT(cbent, next);
|
||||
next = LIST_NEXT(cbent, next);
|
||||
|
||||
if ((cbent->flags & mask) != masked_val)
|
||||
continue;
|
||||
@ -503,7 +503,7 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred)
|
||||
void
|
||||
evbuffer_invoke_callbacks(struct evbuffer *buffer)
|
||||
{
|
||||
if (TAILQ_EMPTY(&buffer->callbacks)) {
|
||||
if (LIST_EMPTY(&buffer->callbacks)) {
|
||||
buffer->n_add_for_cb = buffer->n_del_for_cb = 0;
|
||||
return;
|
||||
}
|
||||
@ -542,9 +542,9 @@ evbuffer_remove_all_callbacks(struct evbuffer *buffer)
|
||||
{
|
||||
struct evbuffer_cb_entry *cbent;
|
||||
|
||||
while ((cbent = TAILQ_FIRST(&buffer->callbacks))) {
|
||||
TAILQ_REMOVE(&buffer->callbacks, cbent, next);
|
||||
mm_free(cbent);
|
||||
while ((cbent = LIST_FIRST(&buffer->callbacks))) {
|
||||
LIST_REMOVE(cbent, next);
|
||||
mm_free(cbent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3190,7 +3190,7 @@ evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg)
|
||||
{
|
||||
EVBUFFER_LOCK(buffer);
|
||||
|
||||
if (!TAILQ_EMPTY(&buffer->callbacks))
|
||||
if (!LIST_EMPTY(&buffer->callbacks))
|
||||
evbuffer_remove_all_callbacks(buffer);
|
||||
|
||||
if (cb) {
|
||||
@ -3212,7 +3212,7 @@ evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg)
|
||||
e->cb.cb_func = cb;
|
||||
e->cbarg = cbarg;
|
||||
e->flags = EVBUFFER_CB_ENABLED;
|
||||
TAILQ_INSERT_HEAD(&buffer->callbacks, e, next);
|
||||
LIST_INSERT_HEAD(&buffer->callbacks, e, next);
|
||||
EVBUFFER_UNLOCK(buffer);
|
||||
return e;
|
||||
}
|
||||
@ -3222,7 +3222,7 @@ evbuffer_remove_cb_entry(struct evbuffer *buffer,
|
||||
struct evbuffer_cb_entry *ent)
|
||||
{
|
||||
EVBUFFER_LOCK(buffer);
|
||||
TAILQ_REMOVE(&buffer->callbacks, ent, next);
|
||||
LIST_REMOVE(ent, next);
|
||||
EVBUFFER_UNLOCK(buffer);
|
||||
mm_free(ent);
|
||||
return 0;
|
||||
@ -3234,7 +3234,7 @@ evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg)
|
||||
struct evbuffer_cb_entry *cbent;
|
||||
int result = -1;
|
||||
EVBUFFER_LOCK(buffer);
|
||||
TAILQ_FOREACH(cbent, &buffer->callbacks, next) {
|
||||
LIST_FOREACH(cbent, &buffer->callbacks, next) {
|
||||
if (cb == cbent->cb.cb_func && cbarg == cbent->cbarg) {
|
||||
result = evbuffer_remove_cb_entry(buffer, cbent);
|
||||
goto done;
|
||||
|
@ -157,7 +157,7 @@ evbuffer_overlapped_new(evutil_socket_t fd)
|
||||
if (!evo)
|
||||
return NULL;
|
||||
|
||||
TAILQ_INIT(&evo->buffer.callbacks);
|
||||
LIST_INIT(&evo->buffer.callbacks);
|
||||
evo->buffer.refcnt = 1;
|
||||
evo->buffer.last_with_datap = &evo->buffer.first;
|
||||
|
||||
|
@ -66,7 +66,7 @@ typedef ev_uint16_t bufferevent_suspend_flags;
|
||||
|
||||
struct bufferevent_rate_limit_group {
|
||||
/** List of all members in the group */
|
||||
TAILQ_HEAD(rlim_group_member_list, bufferevent_private) members;
|
||||
LIST_HEAD(rlim_group_member_list, bufferevent_private) members;
|
||||
/** Current limits for the group. */
|
||||
struct ev_token_bucket rate_limit;
|
||||
struct ev_token_bucket_cfg rate_limit_cfg;
|
||||
@ -117,7 +117,7 @@ struct bufferevent_rate_limit {
|
||||
*
|
||||
* Note that this field is supposed to be protected by the group
|
||||
* lock */
|
||||
TAILQ_ENTRY(bufferevent_private) next_in_group;
|
||||
LIST_ENTRY(bufferevent_private) next_in_group;
|
||||
/** The rate-limiting group for this bufferevent, or NULL if it is
|
||||
* only rate-limited on its own. */
|
||||
struct bufferevent_rate_limit_group *group;
|
||||
|
@ -360,7 +360,7 @@ _bev_group_suspend_reading(struct bufferevent_rate_limit_group *g)
|
||||
bufferevent, it will find out later when it looks at its limit
|
||||
and sees that its group is suspended.
|
||||
*/
|
||||
TAILQ_FOREACH(bev, &g->members, rate_limiting->next_in_group) {
|
||||
LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) {
|
||||
if (EVLOCK_TRY_LOCK(bev->lock)) {
|
||||
bufferevent_suspend_read(&bev->bev,
|
||||
BEV_SUSPEND_BW_GROUP);
|
||||
@ -378,7 +378,7 @@ _bev_group_suspend_writing(struct bufferevent_rate_limit_group *g)
|
||||
struct bufferevent_private *bev;
|
||||
g->write_suspended = 1;
|
||||
g->pending_unsuspend_write = 0;
|
||||
TAILQ_FOREACH(bev, &g->members, rate_limiting->next_in_group) {
|
||||
LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) {
|
||||
if (EVLOCK_TRY_LOCK(bev->lock)) {
|
||||
bufferevent_suspend_write(&bev->bev,
|
||||
BEV_SUSPEND_BW_GROUP);
|
||||
@ -450,13 +450,13 @@ _bev_group_random_element(struct bufferevent_rate_limit_group *group)
|
||||
if (!group->n_members)
|
||||
return NULL;
|
||||
|
||||
EVUTIL_ASSERT(! TAILQ_EMPTY(&group->members));
|
||||
EVUTIL_ASSERT(! LIST_EMPTY(&group->members));
|
||||
|
||||
which = _evutil_weakrand() % group->n_members;
|
||||
|
||||
bev = TAILQ_FIRST(&group->members);
|
||||
bev = LIST_FIRST(&group->members);
|
||||
while (which--)
|
||||
bev = TAILQ_NEXT(bev, rate_limiting->next_in_group);
|
||||
bev = LIST_NEXT(bev, rate_limiting->next_in_group);
|
||||
|
||||
return bev;
|
||||
}
|
||||
@ -471,12 +471,12 @@ _bev_group_random_element(struct bufferevent_rate_limit_group *group)
|
||||
#define FOREACH_RANDOM_ORDER(block) \
|
||||
do { \
|
||||
first = _bev_group_random_element(g); \
|
||||
for (bev = first; bev != TAILQ_END(&g->members); \
|
||||
bev = TAILQ_NEXT(bev, rate_limiting->next_in_group)) { \
|
||||
for (bev = first; bev != LIST_END(&g->members); \
|
||||
bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
|
||||
block ; \
|
||||
} \
|
||||
for (bev = TAILQ_FIRST(&g->members); bev && bev != first; \
|
||||
bev = TAILQ_NEXT(bev, rate_limiting->next_in_group)) { \
|
||||
for (bev = LIST_FIRST(&g->members); bev && bev != first; \
|
||||
bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
|
||||
block ; \
|
||||
} \
|
||||
} while (0)
|
||||
@ -647,7 +647,7 @@ bufferevent_rate_limit_group_new(struct event_base *base,
|
||||
if (!g)
|
||||
return NULL;
|
||||
memcpy(&g->rate_limit_cfg, cfg, sizeof(g->rate_limit_cfg));
|
||||
TAILQ_INIT(&g->members);
|
||||
LIST_INIT(&g->members);
|
||||
|
||||
ev_token_bucket_init(&g->rate_limit, cfg, tick, 0);
|
||||
|
||||
@ -757,7 +757,7 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev,
|
||||
LOCK_GROUP(g);
|
||||
bevp->rate_limiting->group = g;
|
||||
++g->n_members;
|
||||
TAILQ_INSERT_TAIL(&g->members, bevp, rate_limiting->next_in_group);
|
||||
LIST_INSERT_HEAD(&g->members, bevp, rate_limiting->next_in_group);
|
||||
|
||||
rsuspend = g->read_suspended;
|
||||
wsuspend = g->write_suspended;
|
||||
@ -792,7 +792,7 @@ bufferevent_remove_from_rate_limit_group_internal(struct bufferevent *bev,
|
||||
LOCK_GROUP(g);
|
||||
bevp->rate_limiting->group = NULL;
|
||||
--g->n_members;
|
||||
TAILQ_REMOVE(&g->members, bevp, rate_limiting->next_in_group);
|
||||
LIST_REMOVE(bevp, rate_limiting->next_in_group);
|
||||
UNLOCK_GROUP(g);
|
||||
}
|
||||
if (unsuspend) {
|
||||
|
@ -60,7 +60,7 @@ extern "C" {
|
||||
* when bytes are added to or removed from the evbuffer. */
|
||||
struct evbuffer_cb_entry {
|
||||
/** Structures to implement a doubly-linked queue of callbacks */
|
||||
TAILQ_ENTRY(evbuffer_cb_entry) next;
|
||||
LIST_ENTRY(evbuffer_cb_entry) next;
|
||||
/** The callback function to invoke when this callback is called.
|
||||
If EVBUFFER_CB_OBSOLETE is set in flags, the cb_obsolete field is
|
||||
valid; otherwise, cb_func is valid. */
|
||||
@ -147,7 +147,7 @@ struct evbuffer {
|
||||
struct deferred_cb deferred;
|
||||
|
||||
/** A doubly-linked-list of callback functions */
|
||||
TAILQ_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks;
|
||||
LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks;
|
||||
|
||||
/** The parent bufferevent object this evbuffer belongs to.
|
||||
* NULL if the evbuffer stands alone. */
|
||||
|
28
evmap.c
28
evmap.c
@ -56,7 +56,7 @@
|
||||
write on a given fd, and the number of each.
|
||||
*/
|
||||
struct evmap_io {
|
||||
struct event_list events;
|
||||
struct event_dlist events;
|
||||
ev_uint16_t nread;
|
||||
ev_uint16_t nwrite;
|
||||
};
|
||||
@ -64,7 +64,7 @@ struct evmap_io {
|
||||
/* An entry for an evmap_signal list: notes all the events that want to know
|
||||
when a signal triggers. */
|
||||
struct evmap_signal {
|
||||
struct event_list events;
|
||||
struct event_dlist events;
|
||||
};
|
||||
|
||||
/* On some platforms, fds start at 0 and increment by 1 as they are
|
||||
@ -252,7 +252,7 @@ evmap_signal_clear(struct event_signal_map *ctx)
|
||||
static void
|
||||
evmap_io_init(struct evmap_io *entry)
|
||||
{
|
||||
TAILQ_INIT(&entry->events);
|
||||
LIST_INIT(&entry->events);
|
||||
entry->nread = 0;
|
||||
entry->nwrite = 0;
|
||||
}
|
||||
@ -306,7 +306,7 @@ evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev)
|
||||
return -1;
|
||||
}
|
||||
if (EVENT_DEBUG_MODE_IS_ON() &&
|
||||
(old_ev = TAILQ_FIRST(&ctx->events)) &&
|
||||
(old_ev = LIST_FIRST(&ctx->events)) &&
|
||||
(old_ev->ev_events&EV_ET) != (ev->ev_events&EV_ET)) {
|
||||
event_warnx("Tried to mix edge-triggered and non-edge-triggered"
|
||||
" events on fd %d", (int)fd);
|
||||
@ -326,7 +326,7 @@ evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev)
|
||||
|
||||
ctx->nread = (ev_uint16_t) nread;
|
||||
ctx->nwrite = (ev_uint16_t) nwrite;
|
||||
TAILQ_INSERT_TAIL(&ctx->events, ev, ev_io_next);
|
||||
LIST_INSERT_HEAD(&ctx->events, ev, ev_io_next);
|
||||
|
||||
return (retval);
|
||||
}
|
||||
@ -382,7 +382,7 @@ evmap_io_del(struct event_base *base, evutil_socket_t fd, struct event *ev)
|
||||
|
||||
ctx->nread = nread;
|
||||
ctx->nwrite = nwrite;
|
||||
TAILQ_REMOVE(&ctx->events, ev, ev_io_next);
|
||||
LIST_REMOVE(ev, ev_io_next);
|
||||
|
||||
return (retval);
|
||||
}
|
||||
@ -400,7 +400,7 @@ evmap_io_active(struct event_base *base, evutil_socket_t fd, short events)
|
||||
GET_IO_SLOT(ctx, io, fd, evmap_io);
|
||||
|
||||
EVUTIL_ASSERT(ctx);
|
||||
TAILQ_FOREACH(ev, &ctx->events, ev_io_next) {
|
||||
LIST_FOREACH(ev, &ctx->events, ev_io_next) {
|
||||
if (ev->ev_events & events)
|
||||
event_active_nolock(ev, ev->ev_events & events, 1);
|
||||
}
|
||||
@ -411,7 +411,7 @@ evmap_io_active(struct event_base *base, evutil_socket_t fd, short events)
|
||||
static void
|
||||
evmap_signal_init(struct evmap_signal *entry)
|
||||
{
|
||||
TAILQ_INIT(&entry->events);
|
||||
LIST_INIT(&entry->events);
|
||||
}
|
||||
|
||||
|
||||
@ -430,13 +430,13 @@ evmap_signal_add(struct event_base *base, int sig, struct event *ev)
|
||||
GET_SIGNAL_SLOT_AND_CTOR(ctx, map, sig, evmap_signal, evmap_signal_init,
|
||||
base->evsigsel->fdinfo_len);
|
||||
|
||||
if (TAILQ_EMPTY(&ctx->events)) {
|
||||
if (LIST_EMPTY(&ctx->events)) {
|
||||
if (evsel->add(base, ev->ev_fd, 0, EV_SIGNAL, NULL)
|
||||
== -1)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&ctx->events, ev, ev_signal_next);
|
||||
LIST_INSERT_HEAD(&ctx->events, ev, ev_signal_next);
|
||||
|
||||
return (1);
|
||||
}
|
||||
@ -453,13 +453,13 @@ evmap_signal_del(struct event_base *base, int sig, struct event *ev)
|
||||
|
||||
GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal);
|
||||
|
||||
if (TAILQ_FIRST(&ctx->events) == TAILQ_LAST(&ctx->events, event_list)) {
|
||||
LIST_REMOVE(ev, ev_signal_next);
|
||||
|
||||
if (LIST_FIRST(&ctx->events) == NULL) {
|
||||
if (evsel->del(base, ev->ev_fd, 0, EV_SIGNAL, NULL) == -1)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&ctx->events, ev, ev_signal_next);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -473,7 +473,7 @@ evmap_signal_active(struct event_base *base, evutil_socket_t sig, int ncalls)
|
||||
EVUTIL_ASSERT(sig < map->nentries);
|
||||
GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal);
|
||||
|
||||
TAILQ_FOREACH(ev, &ctx->events, ev_signal_next)
|
||||
LIST_FOREACH(ev, &ctx->events, ev_signal_next)
|
||||
event_active_nolock(ev, EV_SIGNAL, ncalls);
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,16 @@ struct name { \
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fix so that people don't have to run with <sys/queue.h> */
|
||||
#ifndef LIST_ENTRY
|
||||
#define _EVENT_DEFINED_LISTENTRY
|
||||
#define LIST_ENTRY(type) \
|
||||
struct { \
|
||||
struct type *le_next; /* next element */ \
|
||||
struct type **le_prev; /* address of previous next element */ \
|
||||
}
|
||||
#endif /* !TAILQ_ENTRY */
|
||||
|
||||
struct event_base;
|
||||
struct event {
|
||||
TAILQ_ENTRY(event) ev_active_next;
|
||||
@ -99,13 +109,13 @@ struct event {
|
||||
union {
|
||||
/* used for io events */
|
||||
struct {
|
||||
TAILQ_ENTRY(event) ev_io_next;
|
||||
LIST_ENTRY (event) ev_io_next;
|
||||
struct timeval ev_timeout;
|
||||
} ev_io;
|
||||
|
||||
/* used by signal events */
|
||||
struct {
|
||||
TAILQ_ENTRY(event) ev_signal_next;
|
||||
LIST_ENTRY (event) ev_signal_next;
|
||||
short ev_ncalls;
|
||||
/* Allows deletes in callback */
|
||||
short *ev_pncalls;
|
||||
@ -134,6 +144,14 @@ TAILQ_HEAD (event_list, event);
|
||||
#undef TAILQ_HEAD
|
||||
#endif
|
||||
|
||||
#ifdef _EVENT_DEFINED_LISTENTRY
|
||||
#undef LIST_ENTRY
|
||||
struct event_dlist;
|
||||
#undef _EVENT_DEFINED_LISTENTRY
|
||||
#else
|
||||
LIST_HEAD (event_dlist, event);
|
||||
#endif /* _EVENT_DEFINED_LISTENTRY */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user