mirror of
https://github.com/cuberite/libevent.git
synced 2025-08-04 01:36:23 -04:00
Minor optimizations on bufferevent_trigger options
By making BEV_TRIG_DEFER_CALLBACKS equal to BEV_OPT_DEFER_CALLBACKS, and BEV_TRIG_IGNORE_WATERMARKS disjoint from BEV_OPT_*, we can save a few operations in bufferevent_run_*, which is critical-path.
This commit is contained in:
parent
4dd3abd41f
commit
a3172a415b
@ -226,8 +226,7 @@ bufferevent_run_readcb_(struct bufferevent *bufev, int options)
|
|||||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||||
if (bufev->readcb == NULL)
|
if (bufev->readcb == NULL)
|
||||||
return;
|
return;
|
||||||
if ((p->options & BEV_OPT_DEFER_CALLBACKS) ||
|
if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
|
||||||
(options & BEV_TRIG_DEFER_CALLBACKS)) {
|
|
||||||
p->readcb_pending = 1;
|
p->readcb_pending = 1;
|
||||||
SCHEDULE_DEFERRED(p);
|
SCHEDULE_DEFERRED(p);
|
||||||
} else {
|
} else {
|
||||||
@ -243,8 +242,7 @@ bufferevent_run_writecb_(struct bufferevent *bufev, int options)
|
|||||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||||
if (bufev->writecb == NULL)
|
if (bufev->writecb == NULL)
|
||||||
return;
|
return;
|
||||||
if ((p->options & BEV_OPT_DEFER_CALLBACKS) ||
|
if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
|
||||||
(options & BEV_TRIG_DEFER_CALLBACKS)) {
|
|
||||||
p->writecb_pending = 1;
|
p->writecb_pending = 1;
|
||||||
SCHEDULE_DEFERRED(p);
|
SCHEDULE_DEFERRED(p);
|
||||||
} else {
|
} else {
|
||||||
@ -252,11 +250,16 @@ bufferevent_run_writecb_(struct bufferevent *bufev, int options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BEV_TRIG_ALL_OPTS ( \
|
||||||
|
BEV_TRIG_IGNORE_WATERMARKS| \
|
||||||
|
BEV_TRIG_DEFER_CALLBACKS \
|
||||||
|
)
|
||||||
|
|
||||||
void
|
void
|
||||||
bufferevent_trigger(struct bufferevent *bufev, short iotype, int options)
|
bufferevent_trigger(struct bufferevent *bufev, short iotype, int options)
|
||||||
{
|
{
|
||||||
bufferevent_incref_and_lock_(bufev);
|
bufferevent_incref_and_lock_(bufev);
|
||||||
bufferevent_trigger_nolock_(bufev, iotype, options);
|
bufferevent_trigger_nolock_(bufev, iotype, options&BEV_TRIG_ALL_OPTS);
|
||||||
bufferevent_decref_and_unlock_(bufev);
|
bufferevent_decref_and_unlock_(bufev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,8 +271,7 @@ bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options)
|
|||||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||||
if (bufev->errorcb == NULL)
|
if (bufev->errorcb == NULL)
|
||||||
return;
|
return;
|
||||||
if ((p->options & BEV_OPT_DEFER_CALLBACKS) ||
|
if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) {
|
||||||
(options & BEV_TRIG_DEFER_CALLBACKS)) {
|
|
||||||
p->eventcb_pending |= what;
|
p->eventcb_pending |= what;
|
||||||
p->errno_pending = EVUTIL_SOCKET_ERROR();
|
p->errno_pending = EVUTIL_SOCKET_ERROR();
|
||||||
SCHEDULE_DEFERRED(p);
|
SCHEDULE_DEFERRED(p);
|
||||||
@ -282,7 +284,7 @@ void
|
|||||||
bufferevent_trigger_event(struct bufferevent *bufev, short what, int options)
|
bufferevent_trigger_event(struct bufferevent *bufev, short what, int options)
|
||||||
{
|
{
|
||||||
bufferevent_incref_and_lock_(bufev);
|
bufferevent_incref_and_lock_(bufev);
|
||||||
bufferevent_run_eventcb_(bufev, what, options);
|
bufferevent_run_eventcb_(bufev, what, options&BEV_TRIG_ALL_OPTS);
|
||||||
bufferevent_decref_and_unlock_(bufev);
|
bufferevent_decref_and_unlock_(bufev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,10 +564,13 @@ int bufferevent_flush(struct bufferevent *bufev,
|
|||||||
*/
|
*/
|
||||||
enum bufferevent_trigger_options {
|
enum bufferevent_trigger_options {
|
||||||
/** trigger the callback regardless of the watermarks */
|
/** trigger the callback regardless of the watermarks */
|
||||||
BEV_TRIG_IGNORE_WATERMARKS = (1<<0),
|
BEV_TRIG_IGNORE_WATERMARKS = (1<<16),
|
||||||
|
|
||||||
/** defer even if the callbacks are not */
|
/** defer even if the callbacks are not */
|
||||||
BEV_TRIG_DEFER_CALLBACKS = (1<<1),
|
BEV_TRIG_DEFER_CALLBACKS = BEV_OPT_DEFER_CALLBACKS,
|
||||||
|
|
||||||
|
/* (Note: for internal reasons, these need to be disjoint from
|
||||||
|
* bufferevent_options, except when they mean the same thing. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user