Fixes for _WIN32. Eliminates the use of MAKE_STATIC and the DllMain constructor.

git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@630 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
mheily 2013-01-25 02:43:43 +00:00
parent c7ed4e84f3
commit 757116ae6a
4 changed files with 28 additions and 41 deletions

View File

@ -86,7 +86,6 @@ include_directories(
option(STATIC_KQUEUE "Enable to build libkqueue as static lib" OFF)
if(STATIC_KQUEUE)
message("-- building libkqueue as static lib")
add_definitions(-DMAKE_STATIC)
add_library(kqueue STATIC ${SRC} ${INCL})
else()
add_library(kqueue SHARED ${SRC} ${INCL})

View File

@ -27,7 +27,10 @@
int DEBUG_KQUEUE = 0;
char *KQUEUE_DEBUG_IDENT = "KQ";
#ifndef _WIN32
#ifdef _WIN32
static LONG kq_init_begin = 0;
static int kq_init_complete = 0;
#else
pthread_mutex_t kq_mtx = PTHREAD_MUTEX_INITIALIZER;
pthread_once_t kq_is_initialized = PTHREAD_ONCE_INIT;
#endif
@ -56,7 +59,6 @@ get_fd_limit(void)
static struct map *kqmap;
void
libkqueue_init(void)
{
@ -66,6 +68,14 @@ libkqueue_init(void)
char *s = getenv("KQUEUE_DEBUG");
if (s != NULL && strlen(s) > 0) {
DEBUG_KQUEUE = 1;
#ifdef _WIN32
/* Initialize the Winsock library */
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
abort();
#endif
# if defined(_WIN32) && !defined(__GNUC__)
/* Enable heap surveillance */
{
@ -83,6 +93,9 @@ libkqueue_init(void)
if (knote_init() < 0)
abort();
dbg_puts("library initialization complete");
#ifdef _WIN32
kq_init_complete = 1;
#endif
}
#if DEADWOOD
@ -116,7 +129,15 @@ kqueue(void)
struct kqueue *kq;
struct kqueue *tmp;
#ifndef _WIN32
#ifdef _WIN32
if (InterlockedCompareExchange(&kq_init_begin, 0, 1) == 0) {
libkqueue_init();
} else {
while (kq_init_complete == 0) {
sleep(1);
}
}
#else
(void) pthread_mutex_lock(&kq_mtx);
(void) pthread_once(&kq_is_initialized, libkqueue_init);
(void) pthread_mutex_unlock(&kq_mtx);

View File

@ -43,36 +43,6 @@ const struct kqueue_vtable kqops = {
windows_filter_free,
};
#ifndef MAKE_STATIC
BOOL WINAPI DllMain(
HINSTANCE self,
DWORD reason,
LPVOID unused)
{
switch (reason) {
case DLL_PROCESS_ATTACH:
#if XXX
//move to EVFILT_READ?
if (WSAStartup(MAKEWORD(2,2), NULL) != 0)
return (FALSE);
#endif
libkqueue_init();
break;
case DLL_PROCESS_DETACH:
#if XXX
WSACleanup();
#endif
break;
}
return (TRUE);
}
#endif
int
windows_kqueue_init(struct kqueue *kq)
{

View File

@ -188,7 +188,7 @@ test_harness(struct unit_test tests[], int iterations, int concurrency)
abort();
ctx->iteration = n++;
ctx->kqfd = kqfd;
memcpy(&ctx->tests, tests, sizeof(ctx->tests)); //FIXME: invalid read
memcpy(&ctx->tests, tests, sizeof(*tests));
ctx->iterations = iterations;
ctx->concurrency = concurrency;
@ -254,10 +254,6 @@ main(int argc, char **argv)
char *arg;
int match;
#ifdef MAKE_STATIC
libkqueue_init();
#endif
#ifdef _WIN32
/* Initialize the Winsock library */
WSADATA wsaData;
@ -265,10 +261,11 @@ main(int argc, char **argv)
err(1, "WSAStartup failed");
#endif
/* Windows does not provide a POSIX-compatible getopt */
#ifndef _WIN32
iterations = 1;
concurrency = 1;
/* Windows does not provide a POSIX-compatible getopt */
#ifndef _WIN32
while ((c = getopt (argc, argv, "hc:n:")) != -1) {
switch (c) {
case 'c':