Don't try to make notifiable event_base when no threading fns are configured

This commit is contained in:
Nick Mathewson 2011-11-14 17:33:02 -05:00
parent 4e797f388f
commit e787413329
3 changed files with 18 additions and 1 deletions

View File

@ -625,7 +625,8 @@ event_base_new_with_config(const struct event_config *cfg)
/* prepare for threading */ /* prepare for threading */
#ifndef _EVENT_DISABLE_THREAD_SUPPORT #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; int r;
EVTHREAD_ALLOC_LOCK(base->th_base_lock, EVTHREAD_ALLOC_LOCK(base->th_base_lock,
EVTHREAD_LOCKTYPE_RECURSIVE); EVTHREAD_LOCKTYPE_RECURSIVE);

View File

@ -173,6 +173,10 @@ EVLOCK_TRY_LOCK(void *lock)
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \ #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
( (cond) ? _evthread_cond_fns.wait_condition((cond), (lock), (tv)) : 0 ) ( (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) #elif ! defined(_EVENT_DISABLE_THREAD_SUPPORT)
unsigned long _evthreadimpl_get_id(void); unsigned long _evthreadimpl_get_id(void);
@ -185,6 +189,7 @@ void *_evthreadimpl_cond_alloc(unsigned condtype);
void _evthreadimpl_cond_free(void *cond); void _evthreadimpl_cond_free(void *cond);
int _evthreadimpl_cond_signal(void *cond, int broadcast); int _evthreadimpl_cond_signal(void *cond, int broadcast);
int _evthreadimpl_cond_wait(void *cond, void *lock, const struct timeval *tv); 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 EVTHREAD_GET_ID() _evthreadimpl_get_id()
#define EVBASE_IN_THREAD(base) \ #define EVBASE_IN_THREAD(base) \
@ -281,6 +286,9 @@ EVLOCK_TRY_LOCK(void *lock)
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \ #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \
( (cond) ? _evthreadimpl_cond_wait((cond), (lock), (tv)) : 0 ) ( (cond) ? _evthreadimpl_cond_wait((cond), (lock), (tv)) : 0 )
#define EVTHREAD_LOCKING_ENABLED() \
(_evthreadimpl_locking_enabled())
#else /* _EVENT_DISABLE_THREAD_SUPPORT */ #else /* _EVENT_DISABLE_THREAD_SUPPORT */
#define EVTHREAD_GET_ID() 1 #define EVTHREAD_GET_ID() 1
@ -307,6 +315,8 @@ EVLOCK_TRY_LOCK(void *lock)
#define EVTHREAD_COND_WAIT(cond, lock) _EVUTIL_NIL_STMT #define EVTHREAD_COND_WAIT(cond, lock) _EVUTIL_NIL_STMT
#define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) _EVUTIL_NIL_STMT #define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) _EVUTIL_NIL_STMT
#define EVTHREAD_LOCKING_ENABLED() 0
#endif #endif
/* This code is shared between both lock impls */ /* This code is shared between both lock impls */

View File

@ -425,6 +425,12 @@ _evthreadimpl_is_lock_debugging_enabled(void)
{ {
return _evthread_lock_debugging_enabled; return _evthread_lock_debugging_enabled;
} }
int
_evthreadimpl_locking_enabled(void)
{
return _evthread_lock_fns.lock != NULL;
}
#endif #endif
#endif #endif