]> granicus.if.org Git - libevent/commit
Debug mode option to error on evthread init AFTER other event calls.
authorMark Ellzey <socket@gmail.com>
Fri, 15 May 2015 09:58:14 +0000 (02:58 -0700)
committerMark Ellzey <socket@gmail.com>
Fri, 15 May 2015 09:58:14 +0000 (02:58 -0700)
commitdcfb19a27b7760299bc9e7291c9abd88c59fd91a
tree67bd1362a92dcde89186c52492d73bfd4b676c09
parent6c8cb5ef7edd72547761d0a62a5e872a1423c8f5
Debug mode option to error on evthread init AFTER other event calls.

- A handy event_enable_debug_mode() feature which will error and abort the
  application if any thread-aware libevent functions are called BEFORE the
  evthread API has been initialized (manually, or through
  evthread_use_windows_threads() / evthread_use_pthreads()

- This is done by setting the global debug variable
  'event_debug_created_threadable_ctx_' whenever the following functions
  are called:

     evthreadimpl_lock_alloc_()
     evthreadimpl_cond_alloc_()
     event_base_new_with_config() <- this checks to see if the thread
                                     callbacks are enabled first, so we
                                     have to manually set the variable.

- Example:

int main(int argc, char ** argv) {
    struct event_base * base;

    event_enable_debug_mode();

    base = event_base_new();

    evthread_use_pthreads();

    return 0;
}

When executed, the program will throw an error and exit:

[err] evthread initialization must be called BEFORE anything else!
event.c
evthread.c