mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 11:53:00 -04:00
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
This commit is contained in:
parent
9cf4ee7e17
commit
1fb2e818a6
@ -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
|
||||
|
18
event.c
18
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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user