evthread: add evthread_get_{lock,condition}_callbacks() helpers

This commit is contained in:
Azat Khuzhin 2015-01-26 00:27:41 +03:00
parent 92a359ee3a
commit c0b34f6fd5
2 changed files with 18 additions and 6 deletions

View File

@ -376,6 +376,11 @@ int evsig_global_setup_locks_(const int enable_locks);
int evutil_global_setup_locks_(const int enable_locks);
int evutil_secure_rng_global_setup_locks_(const int enable_locks);
/** Return current evthread_lock_callbacks */
struct evthread_lock_callbacks *evthread_get_lock_callbacks();
/** Return current evthread_condition_callbacks */
struct evthread_condition_callbacks *evthread_get_condition_callbacks();
#endif
#ifdef __cplusplus

View File

@ -69,12 +69,21 @@ evthread_set_id_callback(unsigned long (*id_fn)(void))
evthread_id_fn_ = id_fn;
}
struct evthread_lock_callbacks *evthread_get_lock_callbacks()
{
return evthread_lock_debugging_enabled_
? &original_lock_fns_ : &evthread_lock_fns_;
}
struct evthread_condition_callbacks *evthread_get_condition_callbacks()
{
return evthread_lock_debugging_enabled_
? &original_cond_fns_ : &evthread_cond_fns_;
}
int
evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs)
{
struct evthread_lock_callbacks *target =
evthread_lock_debugging_enabled_
? &original_lock_fns_ : &evthread_lock_fns_;
struct evthread_lock_callbacks *target = evthread_get_lock_callbacks();
if (!cbs) {
if (target->alloc)
@ -109,9 +118,7 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs)
int
evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs)
{
struct evthread_condition_callbacks *target =
evthread_lock_debugging_enabled_
? &original_cond_fns_ : &evthread_cond_fns_;
struct evthread_condition_callbacks *target = evthread_get_condition_callbacks();
if (!cbs) {
if (target->alloc_condition)