#endif
#ifdef WIN32
#include <windows.h>
+#include <process.h>
#endif
struct yaz_thread {
#if YAZ_POSIX_THREADS
pthread_t id;
#else
- void *return_data;
#ifdef WIN32
- HANDLE id;
+ HANDLE handle;
+ void *(*routine)(void *p);
#endif
+ void *data;
#endif
};
+#ifdef WIN32
+unsigned int __stdcall win32_routine(void *p)
+{
+ yaz_thread_t t = (yaz_thread_t) p;
+ void *userdata = t->data;
+ t->data = t->routine(userdata);
+ _endthreadex(0);
+ return 0;
+}
+#endif
+
yaz_thread_t yaz_thread_create(void *(*start_routine)(void *p), void *arg)
{
yaz_thread_t t = xmalloc(sizeof(*t));
t = 0;
}
#else
- t->return_data = start_routine(arg);
+#ifdef WIN32
+ /* we create a wrapper on windows and pass yaz_thread struct to that */
+ unsigned threadID;
+ uintptr_t ex_ret;
+ t->data = arg; /* use data for both input and output */
+ t->routine = start_routine;
+ ex_ret = _beginthreadex(NULL, 0, win32_routine, t, 0, &threadID);
+ if (ex_ret == -1L)
+ {
+ xfree(t);
+ t = 0;
+ }
+ t->handle = (HANDLE) ex_ret;
+#else
+ t->data = start_routine(arg);
+#endif
#endif
return t;
}
#ifdef YAZ_POSIX_THREADS
pthread_join((*tp)->id, value_ptr);
#else
+#ifdef WIN32
+ WaitForSingleObject((*tp)->handle, INFINITE);
+ CloseHandle((*tp)->handle);
+#endif
if (value_ptr)
- *value_ptr = (*tp)->return_data;
+ *value_ptr = (*tp)->data;
#endif
xfree(*tp);
*tp = 0;
{
#ifdef YAZ_POSIX_THREADS
pthread_detach((*tp)->id);
+#else
+#ifdef WIN32
+ CloseHandle((*tp)->handle);
+#endif
#endif
xfree(*tp);
*tp = 0;
$(OBJDIR)\iconv_decode_iso5426.obj \
$(OBJDIR)\iconv_decode_danmarc.obj \
$(OBJDIR)\mutex.obj \
+ $(OBJDIR)\thread_create.obj \
$(OBJDIR)\gettimeofday.obj \
$(OBJDIR)\json.obj \
$(OBJDIR)\sc.obj \