]> granicus.if.org Git - libevent/commitdiff
Use a uniform strategy when a function is not working: do not expose
authorNick Mathewson <nickm@torproject.org>
Fri, 17 Jul 2009 21:47:45 +0000 (21:47 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 17 Jul 2009 21:47:45 +0000 (21:47 +0000)
it.

Rather than failing at runtime, it is better to fail at compile or
link time.

svn:r1363

configure.in
event.c
include/event2/thread.h

index 3717cd88b96637a59cb18439cec78ceb2c8bf18b..b356232eb9cac8ed5eb74ab649061c69828619a0 100644 (file)
@@ -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 6b6bb33b3d2bb51135f36436defd1734665c51d7..267f596fd69352691bbfeb3efb535cd4b7299f6d 100644 (file)
--- 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)
index e1dd190a6fab2a6d7754a9272bb8d52d9d2486c1..73593e7596e4a2a56c8ce3f4507ebfe389241550 100644 (file)
@@ -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