summaryrefslogtreecommitdiff
path: root/src/xs_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xs_utils.cpp')
-rw-r--r--src/xs_utils.cpp43
1 files changed, 43 insertions, 0 deletions
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