From fb1209c72bbfd431b61fa4588785586d24ef67c9 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:06:30 +0900 Subject: More MSVC tests added Signed-off-by: Martin Sustrik --- src/xpub.cpp | 2 +- src/xs_utils.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/xpub.cpp b/src/xpub.cpp index b4bc135..d27337e 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -177,7 +177,7 @@ void xs::xpub_t::send_unsubscription (unsigned char *data_, size_t size_, xpub_t *self = (xpub_t*) arg_; blob_t unsub (size_ + 1, 0); unsub [0] = 0; - memcpy (&unsub [1], data_, size_); + memcpy ((void*) (unsub.data () + 1), data_, size_); self->pending.push_back (unsub); } } diff --git a/src/xs_utils.cpp b/src/xs_utils.cpp index e30ffe2..976f540 100644 --- a/src/xs_utils.cpp +++ b/src/xs_utils.cpp @@ -59,3 +59,46 @@ unsigned long xs_stopwatch_stop (void *watch_) free (watch_); return (unsigned long) (end - start); } + +#if defined XS_HAVE_WINDOWS + +struct arg_t +{ + HANDLE handle; + void (*fn) (void *arg); + void *arg; +}; + +extern "C" +{ + static unsigned int __stdcall thread_routine (void *arg_) + { + arg_t *arg = (arg_t*) arg_; + arg->fn (arg->arg); + return 0; + } +} + +void *xs_thread_create (void (*fn_) (void *arg_), void *arg_) +{ + arg_t *arg = (arg_t*) malloc (sizeof (arg_t)); + alloc_assert (arg); + arg->fn = fn_; + arg->arg = arg_; + arg->handle = (HANDLE) _beginthreadex (NULL, 0, + &::thread_routine, (void*) arg, 0 , NULL); + win_assert (arg->handle != NULL); + return (void*) arg; +} + +void xs_thread_join (void *thread_) +{ + arg_t *arg = (arg_t*) thread_; + DWORD rc = WaitForSingleObject (arg->handle, INFINITE); + win_assert (rc != WAIT_FAILED); + BOOL rc2 = CloseHandle (arg->handle); + win_assert (rc2 != 0); + free (arg); +} + +#endif -- cgit v1.2.3