more win32 stuff

git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@392 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
mheily 2011-01-17 01:05:25 +00:00
parent 926fbfd0ec
commit 0e1c7813bf
7 changed files with 33 additions and 53 deletions

View File

@ -172,19 +172,14 @@ extern "C" {
#ifdef _WIN32
#define EVENT_QUEUE struct kqueue *
__declspec(dllexport) EVENT_QUEUE
CreateEventQueue(void);
__declspec(dllexport) int
kqueue(void);
__declspec(dllexport) int
WaitForEventQueueObject(EVENT_QUEUE kq, const struct kevent *changelist, int nchanges,
kevent(int kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout);
__declspec(dllexport) void
DestroyEventQueue(EVENT_QUEUE);
#else
int kqueue(void);
int kevent(int kq, const struct kevent *changelist, int nchanges,

View File

@ -150,9 +150,6 @@ kqueue_get(int kq)
int VISIBLE
kqueue(void)
{
#ifdef _WIN32
static int kqueue_id = 0;
#endif
struct kqueue *kq;
int tmp;
@ -171,13 +168,7 @@ kqueue(void)
KQUEUE_DEBUG = (getenv("KQUEUE_DEBUG") == NULL) ? 0 : 1;
#endif
#ifdef _WIN32
pthread_rwlock_wrlock(&kqtree_mtx);
kqueue_id++;
pthread_rwlock_unlock(&kqtree_mtx);
kq->kq_sockfd[0] = kqueue_id;
kq->kq_sockfd[1] = kqueue_id;
#else
#ifndef _WIN32
if (socketpair(AF_UNIX, SOCK_STREAM, 0, kq->kq_sockfd) < 0)
goto errout_unlocked;
#endif

View File

@ -148,12 +148,8 @@ struct kqueue {
fd_set kq_fds, kq_rfds;
int kq_nfds;
pthread_mutex_t kq_mtx;
KQUEUE_PLATFORM_SPECIFIC;
#ifdef __sun__
int kq_port; /* see: port_create(2) */
TAILQ_HEAD(event_buf_listhead,event_buf) kq_events;
#endif
volatile uint32_t kq_ref;
volatile uint32_t kq_ref;
KQUEUE_PLATFORM_SPECIFIC;
RB_ENTRY(kqueue) entries;
};

View File

@ -29,5 +29,6 @@
extern long int syscall (long int __sysno, ...);
#define THREAD_ID ((pid_t) syscall(__NR_gettid))
#define KQUEUE_PLATFORM_SPECIFIC //
#endif /* ! _KQUEUE_LINUX_PLATFORM_H */

View File

@ -49,6 +49,13 @@ int solaris_kqueue_init(struct kqueue *);
void port_event_dequeue(port_event_t *, struct kqueue *);
/*
* Additional members of struct kqueue
*/
#define KQUEUE_PLATFORM_SPECIFIC \
int kq_port; \
TAILQ_HEAD(event_buf_listhead,event_buf) kq_events
/*
* Data structures
*/

View File

@ -48,41 +48,21 @@ BOOL WINAPI DllMain(
return (TRUE);
}
__declspec(dllexport) EVENT_QUEUE
CreateEventQueue(void)
int
windows_kqueue_init(struct kqueue *kq)
{
EVENT_QUEUE evq;
int kqfd;
kqfd = kqueue();
if (kqfd < 0)
return (NULL);
evq = calloc(1, sizeof(*evq));
if (evq == NULL)
return (NULL);
evq->kq_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (evq->kq_handle == NULL) {
free(evq);
return (NULL);
kq->kq_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
if (kq->kq_handle == NULL) {
dbg_perror("CreatEvent()");
return (-1);
}
return (evq);
}
__declspec(dllexport) int
WaitForEventQueueObject(EVENT_QUEUE kq, const struct kevent *changelist, int nchanges,
struct kevent *eventlist, int nevents,
const struct timespec *timeout)
{
return (0);
}
__declspec(dllexport) void
DestroyEventQueue(EVENT_QUEUE kq)
void
windows_kqueue_free(struct kqueue *kq)
{
CloseHandle(kq->notifier);
CloseHandle(kq->kq_handle);
free(kq);
}

View File

@ -50,6 +50,16 @@
HANDLE kq_events[MAXIMUM_WAIT_OBJECTS]; \
size_t kq_nevents
/*
* Hooks and prototypes
*/
#define kqueue_free_hook windows_kqueue_free
void windows_kqueue_free(struct kqueue *);
#define kqueue_init_hook windows_kqueue_init
int windows_kqueue_init(struct kqueue *);
/* Windows does not support this attribute.
DllMain() is the only available constructor function.
This means the constructor must be called from within DllMain().