mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 04:50:37 -04:00
Make event_count maintainance branchless at the expense of an extra shift. Needs benchmarking
This commit is contained in:
parent
efc4dc503a
commit
d1cee3b1c7
30
event.c
30
event.c
@ -2418,6 +2418,18 @@ timeout_process(struct event_base *base)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (EVLIST_INTERNAL >> 4) != 1
|
||||||
|
#error "Mismatch for value of EVLIST_INTERNAL"
|
||||||
|
#endif
|
||||||
|
/* These are a fancy way to spell
|
||||||
|
if (~ev->ev_flags & EVLIST_INTERNAL)
|
||||||
|
base->event_count--/++;
|
||||||
|
*/
|
||||||
|
#define DECR_EVENT_COUNT(base,ev) \
|
||||||
|
((base)->event_count -= (~((ev)->ev_flags >> 4) & 1))
|
||||||
|
#define INCR_EVENT_COUNT(base, ev) \
|
||||||
|
((base)->event_count += (~((ev)->ev_flags >> 4) & 1))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
event_queue_remove_inserted(struct event_base *base, struct event *ev)
|
event_queue_remove_inserted(struct event_base *base, struct event *ev)
|
||||||
{
|
{
|
||||||
@ -2427,8 +2439,7 @@ event_queue_remove_inserted(struct event_base *base, struct event *ev)
|
|||||||
ev, ev->ev_fd, EVLIST_INSERTED);
|
ev, ev->ev_fd, EVLIST_INSERTED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
DECR_EVENT_COUNT(base, ev);
|
||||||
base->event_count--;
|
|
||||||
ev->ev_flags &= ~EVLIST_INSERTED;
|
ev->ev_flags &= ~EVLIST_INSERTED;
|
||||||
TAILQ_REMOVE(&base->eventqueue, ev, ev_next);
|
TAILQ_REMOVE(&base->eventqueue, ev, ev_next);
|
||||||
}
|
}
|
||||||
@ -2441,8 +2452,7 @@ event_queue_remove_active(struct event_base *base, struct event *ev)
|
|||||||
ev, ev->ev_fd, EVLIST_ACTIVE);
|
ev, ev->ev_fd, EVLIST_ACTIVE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
DECR_EVENT_COUNT(base, ev);
|
||||||
base->event_count--;
|
|
||||||
ev->ev_flags &= ~EVLIST_ACTIVE;
|
ev->ev_flags &= ~EVLIST_ACTIVE;
|
||||||
base->event_count_active--;
|
base->event_count_active--;
|
||||||
TAILQ_REMOVE(&base->activequeues[ev->ev_pri],
|
TAILQ_REMOVE(&base->activequeues[ev->ev_pri],
|
||||||
@ -2457,8 +2467,7 @@ event_queue_remove_timeout(struct event_base *base, struct event *ev)
|
|||||||
ev, ev->ev_fd, EVLIST_TIMEOUT);
|
ev, ev->ev_fd, EVLIST_TIMEOUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
DECR_EVENT_COUNT(base, ev);
|
||||||
base->event_count--;
|
|
||||||
ev->ev_flags &= ~EVLIST_TIMEOUT;
|
ev->ev_flags &= ~EVLIST_TIMEOUT;
|
||||||
|
|
||||||
if (is_common_timeout(&ev->ev_timeout, base)) {
|
if (is_common_timeout(&ev->ev_timeout, base)) {
|
||||||
@ -2513,8 +2522,7 @@ event_queue_insert_inserted(struct event_base *base, struct event *ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
INCR_EVENT_COUNT(base, ev);
|
||||||
base->event_count++;
|
|
||||||
|
|
||||||
ev->ev_flags |= EVLIST_INSERTED;
|
ev->ev_flags |= EVLIST_INSERTED;
|
||||||
|
|
||||||
@ -2531,8 +2539,7 @@ event_queue_insert_active(struct event_base *base, struct event *ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
INCR_EVENT_COUNT(base, ev);
|
||||||
base->event_count++;
|
|
||||||
|
|
||||||
ev->ev_flags |= EVLIST_ACTIVE;
|
ev->ev_flags |= EVLIST_ACTIVE;
|
||||||
|
|
||||||
@ -2552,8 +2559,7 @@ event_queue_insert_timeout(struct event_base *base, struct event *ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (~ev->ev_flags & EVLIST_INTERNAL)
|
INCR_EVENT_COUNT(base, ev);
|
||||||
base->event_count++;
|
|
||||||
|
|
||||||
ev->ev_flags |= EVLIST_TIMEOUT;
|
ev->ev_flags |= EVLIST_TIMEOUT;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user