From 1fb2e818a6273571c01aed5ccce30a5d846a1663 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 17 Jul 2009 21:47:45 +0000 Subject: [PATCH] Use a uniform strategy when a function is not working: do not expose it. Rather than failing at runtime, it is better to fail at compile or link time. svn:r1363 --- configure.in | 2 +- event.c | 18 ++++++------------ include/event2/thread.h | 21 +++++++++++++-------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/configure.in b/configure.in index 3717cd88..b356232e 100644 --- a/configure.in +++ b/configure.in @@ -420,7 +420,7 @@ ACX_PTHREAD([ AC_DEFINE(HAVE_PTHREADS, 1, [Define if we have pthreads on this system]) have_pthreads=yes]) -AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no"]) +AM_CONDITIONAL(PTHREADS, [test "$have_pthreads" != "no" && test "$enable_thread_support" != "no"]) # check if we should compile locking into the library if test x$enable_thread_support = xno; then diff --git a/event.c b/event.c index 6b6bb33b..267f596f 100644 --- a/event.c +++ b/event.c @@ -1678,6 +1678,7 @@ event_set_mem_functions(void *(*malloc_fn)(size_t sz), } #endif +#ifndef _EVENT_DISABLE_THREAD_SUPPORT /* support for threading */ void (*_evthread_locking_fn)(int mode, void *lock) = NULL; unsigned long (*_evthread_id_fn)(void) = NULL; @@ -1687,12 +1688,9 @@ void (*_evthread_lock_free_fn)(void *) = NULL; void evthread_set_locking_callback(void (*locking_fn)(int mode, void *lock)) { -#ifdef _EVENT_DISABLE_THREAD_SUPPORT - event_errx(1, "%s: not compiled with thread support", __func__); -#else _evthread_locking_fn = locking_fn; -#endif } +#endif #if defined(_EVENT_HAVE_EVENTFD) && defined(_EVENT_HAVE_SYS_EVENTFD_H) static void @@ -1717,15 +1715,13 @@ evthread_notify_drain_default(evutil_socket_t fd, short what, void *arg) #endif } +#ifndef _EVENT_DISABLE_THREAD_SUPPORT void evthread_set_id_callback(unsigned long (*id_fn)(void)) { -#ifdef _EVENT_DISABLE_THREAD_SUPPORT - event_errx(1, "%s: not compiled with thread support", __func__); -#else _evthread_id_fn = id_fn; -#endif } +#endif int evthread_make_base_notifiable(struct event_base *base) @@ -1789,17 +1785,15 @@ evthread_make_base_notifiable(struct event_base *base) return event_add(&base->th_notify, NULL); } +#ifndef _EVENT_DISABLE_THREAD_SUPPORT void evthread_set_lock_create_callbacks(void *(*alloc_fn)(void), void (*free_fn)(void *)) { -#ifdef _EVENT_DISABLE_THREAD_SUPPORT - event_errx(1, "%s: not compiled with thread support", __func__); -#else _evthread_lock_alloc_fn = alloc_fn; _evthread_lock_free_fn = free_fn; -#endif } +#endif void event_base_dump_events(struct event_base *base, FILE *output) diff --git a/include/event2/thread.h b/include/event2/thread.h index e1dd190a..73593e75 100644 --- a/include/event2/thread.h +++ b/include/event2/thread.h @@ -65,6 +65,8 @@ extern "C" { #define EVTHREAD_WRITE 0x04 #define EVTHREAD_READ 0x08 +#ifndef _EVENT_DISABLE_THREAD_SUPPORT + /** Sets the functions Libevent should use for allocating and freeing locks. This needs to be called in addition to @@ -100,13 +102,7 @@ void evthread_set_locking_callback( void evthread_set_id_callback( unsigned long (*id_fn)(void)); -/** Make sure it's safe to tell an event base to wake up from another thread. - - @return 0 on success, -1 on failure. - */ -int evthread_make_base_notifiable(struct event_base *base); - -#ifdef WIN32 +#if defined(WIN32) && !defined(_EVENT_DISABLE_THREAD_SUPPORT) /** Sets up Libevent for use with Windows builtin locking and thread ID functions. Unavailable if Libevent is not built for Windows. @@ -115,7 +111,7 @@ int evthread_use_windows_threads(void); #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1 #endif -#ifdef _EVENT_HAVE_PTHREADS +#if defined(_EVENT_HAVE_PTHREADS) /** Sets up Libevent for use with Pthreads locking and thread ID functions. Unavailable if Libevent is not build for use with pthreads. Requires libraries to link against Libevent_pthreads as well as Libevent. @@ -125,6 +121,15 @@ int evthread_use_pthreads(void); #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1 #endif +#endif /* _EVENT_DISABLE_THREAD_SUPPORT */ + +/** Make sure it's safe to tell an event base to wake up from another thread. + or a signal handler. + + @return 0 on success, -1 on failure. + */ +int evthread_make_base_notifiable(struct event_base *base); + #ifdef __cplusplus } #endif -- 2.40.0