mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Merge pull request #251 from ellzey/21_err_on_thread_init_ordering
Debug mode option to error on evthread init AFTER other event calls.
This commit is contained in:
commit
c6fffc7547
16
event.c
16
event.c
@ -199,6 +199,20 @@ eq_debug_entry(const struct event_debug_entry *a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int event_debug_mode_on_ = 0;
|
int event_debug_mode_on_ = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief debug mode variable which is set for any function/structure that needs
|
||||||
|
* to be shared across threads (if thread support is enabled).
|
||||||
|
*
|
||||||
|
* When and if evthreads are initialized, this variable will be evaluated,
|
||||||
|
* and if set to something other than zero, this means the evthread setup
|
||||||
|
* functions were called out of order.
|
||||||
|
*
|
||||||
|
* See: "Locks and threading" in the documentation.
|
||||||
|
*/
|
||||||
|
int event_debug_created_threadable_ctx_ = 0;
|
||||||
|
|
||||||
/* Set if it's too late to enable event_debug_mode. */
|
/* Set if it's too late to enable event_debug_mode. */
|
||||||
static int event_debug_mode_too_late = 0;
|
static int event_debug_mode_too_late = 0;
|
||||||
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
#ifndef EVENT__DISABLE_THREAD_SUPPORT
|
||||||
@ -656,6 +670,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
|
||||||
|
event_debug_created_threadable_ctx_ = 1;
|
||||||
|
|
||||||
if (EVTHREAD_LOCKING_ENABLED() &&
|
if (EVTHREAD_LOCKING_ENABLED() &&
|
||||||
(!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK))) {
|
(!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK))) {
|
||||||
int r;
|
int r;
|
||||||
|
33
evthread.c
33
evthread.c
@ -45,6 +45,11 @@
|
|||||||
#define GLOBAL static
|
#define GLOBAL static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef EVENT__DISABLE_DEBUG_MODE
|
||||||
|
extern int event_debug_created_threadable_ctx_;
|
||||||
|
extern int event_debug_mode_on_;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* globals */
|
/* globals */
|
||||||
GLOBAL int evthread_lock_debugging_enabled_ = 0;
|
GLOBAL int evthread_lock_debugging_enabled_ = 0;
|
||||||
GLOBAL struct evthread_lock_callbacks evthread_lock_fns_ = {
|
GLOBAL struct evthread_lock_callbacks evthread_lock_fns_ = {
|
||||||
@ -89,6 +94,14 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs)
|
|||||||
{
|
{
|
||||||
struct evthread_lock_callbacks *target = evthread_get_lock_callbacks();
|
struct evthread_lock_callbacks *target = evthread_get_lock_callbacks();
|
||||||
|
|
||||||
|
#ifndef EVENT__DISABLE_DEBUG_MODE
|
||||||
|
if (event_debug_mode_on_) {
|
||||||
|
if (event_debug_created_threadable_ctx_) {
|
||||||
|
event_errx(1, "evthread initialization must be called BEFORE anything else!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!cbs) {
|
if (!cbs) {
|
||||||
if (target->alloc)
|
if (target->alloc)
|
||||||
event_warnx("Trying to disable lock functions after "
|
event_warnx("Trying to disable lock functions after "
|
||||||
@ -124,6 +137,14 @@ evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs)
|
|||||||
{
|
{
|
||||||
struct evthread_condition_callbacks *target = evthread_get_condition_callbacks();
|
struct evthread_condition_callbacks *target = evthread_get_condition_callbacks();
|
||||||
|
|
||||||
|
#ifndef EVENT__DISABLE_DEBUG_MODE
|
||||||
|
if (event_debug_mode_on_) {
|
||||||
|
if (event_debug_created_threadable_ctx_) {
|
||||||
|
event_errx(1, "evthread initialization must be called BEFORE anything else!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!cbs) {
|
if (!cbs) {
|
||||||
if (target->alloc_condition)
|
if (target->alloc_condition)
|
||||||
event_warnx("Trying to disable condition functions "
|
event_warnx("Trying to disable condition functions "
|
||||||
@ -406,6 +427,12 @@ evthreadimpl_get_id_()
|
|||||||
void *
|
void *
|
||||||
evthreadimpl_lock_alloc_(unsigned locktype)
|
evthreadimpl_lock_alloc_(unsigned locktype)
|
||||||
{
|
{
|
||||||
|
#ifndef EVENT__DISABLE_DEBUG_MODE
|
||||||
|
if (event_debug_mode_on_) {
|
||||||
|
event_debug_created_threadable_ctx_ = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return evthread_lock_fns_.alloc ?
|
return evthread_lock_fns_.alloc ?
|
||||||
evthread_lock_fns_.alloc(locktype) : NULL;
|
evthread_lock_fns_.alloc(locktype) : NULL;
|
||||||
}
|
}
|
||||||
@ -434,6 +461,12 @@ evthreadimpl_lock_unlock_(unsigned mode, void *lock)
|
|||||||
void *
|
void *
|
||||||
evthreadimpl_cond_alloc_(unsigned condtype)
|
evthreadimpl_cond_alloc_(unsigned condtype)
|
||||||
{
|
{
|
||||||
|
#ifndef EVENT__DISABLE_DEBUG_MODE
|
||||||
|
if (event_debug_mode_on_) {
|
||||||
|
event_debug_created_threadable_ctx_ = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return evthread_cond_fns_.alloc_condition ?
|
return evthread_cond_fns_.alloc_condition ?
|
||||||
evthread_cond_fns_.alloc_condition(condtype) : NULL;
|
evthread_cond_fns_.alloc_condition(condtype) : NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user