diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-04-22 12:40:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-04-22 14:06:57 -0400 |
commit | cb6ecee7f6199777c10815ac15aad4d808e7375f (patch) | |
tree | c2fa18a580a144cb1eef7aab6680670922a95914 /evthread.c | |
parent | b683cae3cb98b48c4dc5caa0b1768f7bb13b92f1 (diff) | |
download | libevent-cb6ecee7f6199777c10815ac15aad4d808e7375f.tar.gz |
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.
Diffstat (limited to 'evthread.c')
-rw-r--r-- | evthread.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -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)); } |