updates.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 16 Jul 2001 14:17:58 +0000 (14:17 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 16 Jul 2001 14:17:58 +0000 (14:17 +0000)
lib/silcutil/win32/silcwin32schedule.c
lib/silcutil/win32/silcwin32thread.c

index cd6327c74b0e25849097fee378efce9426d83296..e4a02a54c0e39cce405c4632eeab9fa5d9bd475a 100644 (file)
@@ -166,6 +166,8 @@ int silc_select(int n, fd_set *readfds, fd_set *writefds,
   return -1;
 }
 
+#ifdef SILC_THREADS
+
 /* Internal wakeup context. */
 typedef struct {
   HANDLE wakeup_sema;
@@ -188,7 +190,6 @@ SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
 
 void *silc_schedule_wakeup_init(void *queue)
 {
-#ifdef SILC_THREADS
   SilcWin32Wakeup wakeup;
 
   wakeup = silc_calloc(1, sizeof(*wakeup));
index 76ba902439b0fb2f57fd3f0f5a8815f3e7e7ef19..e88a09f0c4690bbfdf9f7cddad507ef43d6d79cb 100644 (file)
@@ -33,19 +33,19 @@ typedef struct {
   bool waitable;
 } *SilcWin32Thread;
 
-static DWROD silc_thread_tls;
+static DWORD silc_thread_tls;
 
 /* Actual routine that is called by WIN32 when the thread is created.
    We will call the start_func from here. When this returns the thread
    is destroyed. */
 
-int __stdcall silc_thread_win32_start(void *context)
+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();
+  silc_thread_exit(NULL);
 
   return 0;
 }
@@ -54,7 +54,7 @@ SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
                              bool waitable)
 {
   SilcWin32Thread thread;
-  DWROD id;
+  unsigned id;
 
   SILC_LOG_DEBUG(("Creating new thread"));
 
@@ -62,8 +62,8 @@ SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
   thread->start_func = start_func;
   thread->context = context;
   thread->waitable = waitable;
-  thread->thread = _beginthreadex(NULL, 0, silc_thread_win32_start,
-                                 thread, 0, &id);
+  thread->thread = (HANDLE)_beginthreadex(NULL, 0, silc_thread_win32_start,
+                                         (void *)thread, 0, &id);
   if (!thread->thread) {
     SILC_LOG_ERROR(("Could not create new thread"));
     silc_free(thread);
@@ -111,16 +111,18 @@ SilcThread silc_thread_self(void)
 
 bool silc_thread_wait(SilcThread thread, void **exit_value)
 {
-  SILC_LOG_DEBUG(("Waiting for thread %p", thread));
+  SilcWin32Thread self = (SilcWin32Thread)thread;
 
-  if (!thread->waitable)
+  SILC_LOG_DEBUG(("Waiting for thread %p", self));
+
+  if (!self->waitable)
     return FALSE;
 
   /* The thread is waitable thus we will free all memory after the
      WaitForSingleObject returns, the thread is destroyed after that. */
-  WaitForSingleObject(thread->thread, INFINITE);
-  CloseHandle(thread->thread);
-  silc_free(thread);
+  WaitForSingleObject(self->thread, INFINITE);
+  CloseHandle(self->thread);
+  silc_free(self);
   if (exit_value)
     *exit_value = NULL;