Added SILC Server library.
[silc.git] / lib / silcutil / unix / silcunixthread.c
index b4fe5a05c3e30c4ee0e6326f4f93f9c5c413c967..099d75d934865fc8846e2326482a7f232c8c1c3e 100644 (file)
@@ -4,12 +4,11 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 Pekka Riikonen
+  Copyright (C) 2001 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  the Free Software Foundation; version 2 of the License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   GNU General Public License for more details.
 
 */
-/* $Id: */
+/* $Id$ */
 
-#include "silcincludes.h"
-
-#ifdef SILC_THREADS
+#include "silc.h"
 
 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
-                             bool waitable)
+                             SilcBool waitable)
 {
+#ifdef SILC_THREADS
   pthread_attr_t attr;
   pthread_t thread;
   int ret;
@@ -58,28 +56,41 @@ SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
 
   pthread_attr_destroy(&attr);
 
-  SILC_LOG_DEBUG(("Created thread %p", (SilcThread)ret));
+  SILC_LOG_DEBUG(("Created thread %p", (SilcThread)thread));
 
-  return (SilcThread)ret;
+  return (SilcThread)thread;
+#else
+  /* Call thread callback immediately */
+  (*start_func)(context);
+  return NULL;
+#endif
 }
 
 void silc_thread_exit(void *exit_value)
 {
-  pthread_exit(NULL);
+#ifdef SILC_THREADS
+  pthread_exit(exit_value);
+#endif
 }
 
 SilcThread silc_thread_self(void)
 {
+#ifdef SILC_THREADS
   pthread_t self = pthread_self();
   return (SilcThread)self;
+#else
+  return NULL;
+#endif
 }
 
-bool silc_thread_wait(SilcThread thread, void **exit_value)
+SilcBool silc_thread_wait(SilcThread thread, void **exit_value)
 {
+#ifdef SILC_THREADS
   SILC_LOG_DEBUG(("Waiting for thread %p", thread));
   if (!pthread_join(*(pthread_t *)thread, exit_value))
     return TRUE;
   return FALSE;
+#else
+  return FALSE;
+#endif
 }
-
-#endif /* SILC_THREADS */