From cb6ecee7f6199777c10815ac15aad4d808e7375f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 22 Apr 2011 12:40:07 -0400 Subject: [PATCH] Complain if the caller tries to change threading cbs after setting them We never supported this; it was always fraught with errors; and I don't believe there is a good reason to _want_ it to work. --- evthread.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/evthread.c b/evthread.c index 8fd62743..de5272b3 100644 --- a/evthread.c +++ b/evthread.c @@ -76,9 +76,22 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs) ? &_original_lock_fns : &_evthread_lock_fns; if (!cbs) { + if (target->alloc) + event_warnx("Trying to disable lock functions after " + "they have been set up will probaby not work."); memset(target, 0, sizeof(_evthread_lock_fns)); return 0; } + if (target->alloc) { + /* Uh oh; we already had locking callbacks set up.*/ + if (!memcmp(target, cbs, sizeof(_evthread_lock_fns))) { + /* no change -- allow this. */ + return 0; + } + event_warnx("Can't change lock callbacks once they have been " + "initialized."); + return -1; + } if (cbs->alloc && cbs->free && cbs->lock && cbs->unlock) { memcpy(target, cbs, sizeof(_evthread_lock_fns)); return event_global_setup_locks_(1); @@ -95,8 +108,24 @@ evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs) ? &_original_cond_fns : &_evthread_cond_fns; if (!cbs) { + if (target->alloc_condition) + event_warnx("Trying to disable condition functions " + "after they have been set up will probaby not " + "work."); memset(target, 0, sizeof(_evthread_cond_fns)); - } else if (cbs->alloc_condition && cbs->free_condition && + return 0; + } + if (target->alloc_condition) { + /* Uh oh; we already had condition callbacks set up.*/ + if (!memcmp(target, cbs, sizeof(_evthread_cond_fns))) { + /* no change -- allow this. */ + return 0; + } + event_warnx("Can't change condition callbacks once they " + "have been initialized."); + return -1; + } + if (cbs->alloc_condition && cbs->free_condition && cbs->signal_condition && cbs->wait_condition) { memcpy(target, cbs, sizeof(_evthread_cond_fns)); } -- 2.40.0