updates.
[silc.git] / lib / silcutil / win32 / silcwin32thread.c
index e88a09f0c4690bbfdf9f7cddad507ef43d6d79cb..bea9552d43e69443a97e9ded1e652e45b2030460 100644 (file)
@@ -19,6 +19,7 @@
 */
 /* These routines are based on GLib's WIN32 gthread implementation and
    thus credits should go there. */
+/* XXX Is the use of Tls necessary?? */
 /* $Id$ */
 
 #include "silcincludes.h"
@@ -44,15 +45,16 @@ unsigned __stdcall silc_thread_win32_start(void *context)
   SilcWin32Thread thread = (SilcWin32Thread)context;
 
   TlsSetValue(silc_thread_tls, context);
-  thread->start_func(thread->context);
-  silc_thread_exit(NULL);
+  silc_thread_exit(thread->start_func(thread->context));
 
   return 0;
 }
+#endif
 
 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
                              bool waitable)
 {
+#ifdef SILC_THREADS
   SilcWin32Thread thread;
   unsigned id;
 
@@ -71,10 +73,16 @@ SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
   }
 
   return (SilcThread)thread;
+#else
+  /* Call thread callback immediately */
+  (*start_func)(context);
+  return NULL;
+#endif
 }
 
 void silc_thread_exit(void *exit_value)
 {
+#ifdef SILC_THREADS
   SilcWin32Thread thread = TlsGetValue(silc_thread_tls);
   
   if (thread) {
@@ -89,10 +97,12 @@ void silc_thread_exit(void *exit_value)
   }
 
   _endthreadex(0);
+#endif
 }
 
 SilcThread silc_thread_self(void)
 {
+#ifdef SILC_THREADS
   SilcWin32Thread self = TlsGetValue(silc_thread_tls);
 
   if (!self) {
@@ -107,10 +117,14 @@ SilcThread silc_thread_self(void)
   }
 
   return (SilcThread)self;
+#else
+  return NULL;
+#endif
 }
 
 bool silc_thread_wait(SilcThread thread, void **exit_value)
 {
+#ifdef SILC_THREADS
   SilcWin32Thread self = (SilcWin32Thread)thread;
 
   SILC_LOG_DEBUG(("Waiting for thread %p", self));
@@ -127,6 +141,7 @@ bool silc_thread_wait(SilcThread thread, void **exit_value)
     *exit_value = NULL;
 
   return TRUE;
+#else
+  return FALSE;
+#endif
 }
-
-#endif /* SILC_THREADS */