mirror of
https://github.com/darlinghq/darling-libkqueue.git
synced 2024-11-26 21:20:38 +00:00
Use pthread_once() instead of marking libkqueue_init() as a constructor.
This gives the correct behavior for both static and dynamic libraries. git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@591 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
parent
e41cc259a0
commit
1e3ee7ad18
3
BUGS
3
BUGS
@ -1,3 +1,6 @@
|
||||
* On Windows, you need to supply -DMAKE_STATIC in CFLAGS when building the
|
||||
static library. This does not apply when using cmake.
|
||||
|
||||
* When passing a knote pointer to the kernel, the reference count of
|
||||
the knote structure should be incremented. Conversely, when the pointer
|
||||
has been returned from the kernel and the event unregistered from the
|
||||
|
@ -27,6 +27,11 @@
|
||||
int DEBUG_KQUEUE = 0;
|
||||
char *KQUEUE_DEBUG_IDENT = "KQ";
|
||||
|
||||
#ifndef _WIN32
|
||||
pthread_mutex_t kq_mtx = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_once_t kq_is_initialized = PTHREAD_ONCE_INIT;
|
||||
#endif
|
||||
|
||||
static unsigned int
|
||||
get_fd_limit(void)
|
||||
{
|
||||
@ -51,10 +56,7 @@ get_fd_limit(void)
|
||||
|
||||
static struct map *kqmap;
|
||||
|
||||
int CONSTRUCTOR
|
||||
#ifdef MAKE_STATIC
|
||||
VISIBLE
|
||||
#endif
|
||||
static void
|
||||
libkqueue_init(void)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
@ -80,7 +82,6 @@ libkqueue_init(void)
|
||||
if (knote_init() < 0)
|
||||
abort();
|
||||
dbg_puts("library initialization complete");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if DEADWOOD
|
||||
@ -114,6 +115,10 @@ kqueue(void)
|
||||
struct kqueue *kq;
|
||||
struct kqueue *tmp;
|
||||
|
||||
(void) pthread_mutex_lock(&kq_mtx);
|
||||
(void) pthread_once(&kq_is_initialized, libkqueue_init);
|
||||
(void) pthread_mutex_unlock(&kq_mtx);
|
||||
|
||||
kq = calloc(1, sizeof(*kq));
|
||||
if (kq == NULL)
|
||||
return (-1);
|
||||
|
@ -208,6 +208,4 @@ void *map_lookup(struct map *, int);
|
||||
void *map_delete(struct map *, int);
|
||||
void map_free(struct map *);
|
||||
|
||||
int CONSTRUCTOR libkqueue_init(void);
|
||||
|
||||
#endif /* ! _KQUEUE_PRIVATE_H */
|
||||
|
@ -39,11 +39,6 @@
|
||||
/*
|
||||
* GCC-compatible attributes
|
||||
*/
|
||||
#ifdef MAKE_STATIC
|
||||
# define CONSTRUCTOR
|
||||
#else
|
||||
# define CONSTRUCTOR __attribute__ ((constructor))
|
||||
#endif
|
||||
#define VISIBLE __attribute__((visibility("default")))
|
||||
#define HIDDEN __attribute__((visibility("hidden")))
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
@ -58,8 +58,7 @@ BOOL WINAPI DllMain(
|
||||
if (WSAStartup(MAKEWORD(2,2), NULL) != 0)
|
||||
return (FALSE);
|
||||
#endif
|
||||
if (libkqueue_init() < 0)
|
||||
return (FALSE);
|
||||
libkqueue_init();
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
@ -99,12 +99,6 @@ int windows_filter_init(struct kqueue *, struct filter *);
|
||||
void windows_filter_free(struct kqueue *, struct filter *);
|
||||
int windows_get_descriptor_type(struct knote *);
|
||||
|
||||
/* Windows does not support this attribute.
|
||||
DllMain() is the only available constructor function.
|
||||
This means the constructor must be called from within DllMain().
|
||||
*/
|
||||
#define CONSTRUCTOR
|
||||
|
||||
/*
|
||||
* GCC-compatible branch prediction macros
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user