mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Merge remote-tracking branch 'origin/patches-2.0'
This commit is contained in:
commit
f5b937e65f
4
event.c
4
event.c
@ -671,7 +671,8 @@ event_base_new_with_config(const struct event_config *cfg)
|
||||
/* prepare for threading */
|
||||
|
||||
#ifndef _EVENT_DISABLE_THREAD_SUPPORT
|
||||
if (!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK)) {
|
||||
if (EVTHREAD_LOCKING_ENABLED() &&
|
||||
(!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK))) {
|
||||
int r;
|
||||
EVTHREAD_ALLOC_LOCK(base->th_base_lock,
|
||||
EVTHREAD_LOCKTYPE_RECURSIVE);
|
||||
@ -679,6 +680,7 @@ event_base_new_with_config(const struct event_config *cfg)
|
||||
EVTHREAD_ALLOC_COND(base->current_event_cond);
|
||||
r = evthread_make_base_notifiable(base);
|
||||
if (r<0) {
|
||||
event_warnx("%s: Unable to make base notifiable.", __func__);
|
||||
event_base_free(base);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -175,6 +175,10 @@ EVLOCK_TRY_LOCK(void *lock)
|
||||
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
|
||||
( (cond) ? _evthread_cond_fns.wait_condition((cond), (lock), (tv)) : 0 )
|
||||
|
||||
/** True iff locking functions have been configured. */
|
||||
#define EVTHREAD_LOCKING_ENABLED() \
|
||||
(_evthread_lock_fns.lock != NULL)
|
||||
|
||||
#elif ! defined(_EVENT_DISABLE_THREAD_SUPPORT)
|
||||
|
||||
unsigned long _evthreadimpl_get_id(void);
|
||||
@ -187,6 +191,7 @@ void *_evthreadimpl_cond_alloc(unsigned condtype);
|
||||
void _evthreadimpl_cond_free(void *cond);
|
||||
int _evthreadimpl_cond_signal(void *cond, int broadcast);
|
||||
int _evthreadimpl_cond_wait(void *cond, void *lock, const struct timeval *tv);
|
||||
int _evthreadimpl_locking_enabled(void);
|
||||
|
||||
#define EVTHREAD_GET_ID() _evthreadimpl_get_id()
|
||||
#define EVBASE_IN_THREAD(base) \
|
||||
@ -283,6 +288,9 @@ EVLOCK_TRY_LOCK(void *lock)
|
||||
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
|
||||
( (cond) ? _evthreadimpl_cond_wait((cond), (lock), (tv)) : 0 )
|
||||
|
||||
#define EVTHREAD_LOCKING_ENABLED() \
|
||||
(_evthreadimpl_locking_enabled())
|
||||
|
||||
#else /* _EVENT_DISABLE_THREAD_SUPPORT */
|
||||
|
||||
#define EVTHREAD_GET_ID() 1
|
||||
@ -309,6 +317,8 @@ EVLOCK_TRY_LOCK(void *lock)
|
||||
#define EVTHREAD_COND_WAIT(cond, lock) _EVUTIL_NIL_STMT
|
||||
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) _EVUTIL_NIL_STMT
|
||||
|
||||
#define EVTHREAD_LOCKING_ENABLED() 0
|
||||
|
||||
#endif
|
||||
|
||||
/* This code is shared between both lock impls */
|
||||
|
@ -437,6 +437,12 @@ _evthreadimpl_is_lock_debugging_enabled(void)
|
||||
{
|
||||
return _evthread_lock_debugging_enabled;
|
||||
}
|
||||
|
||||
int
|
||||
_evthreadimpl_locking_enabled(void)
|
||||
{
|
||||
return _evthread_lock_fns.lock != NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user