projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added SILC Server library.
[silc.git]
/
lib
/
silcutil
/
win32
/
silcwin32thread.c
diff --git
a/lib/silcutil/win32/silcwin32thread.c
b/lib/silcutil/win32/silcwin32thread.c
index 6e6a90949521ab204206cdc7cd3a2a184f266fc1..c31e70931381d2f68cecb669bb040f462b102839 100644
(file)
--- a/
lib/silcutil/win32/silcwin32thread.c
+++ b/
lib/silcutil/win32/silcwin32thread.c
@@
-4,12
+4,11
@@
Author: Pekka Riikonen <priikone@silcnet.org>
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
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
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-17,11
+16,9
@@
GNU General Public License for more details.
*/
GNU General Public License for more details.
*/
-/* These routines are based on GLib's WIN32 gthread implementation and
- thus credits should go there. */
/* $Id$ */
/* $Id$ */
-#include "silc
includes
.h"
+#include "silc.h"
#ifdef SILC_THREADS
#ifdef SILC_THREADS
@@
-30,7
+27,7
@@
typedef struct {
HANDLE thread;
SilcThreadStart start_func;
void *context;
HANDLE thread;
SilcThreadStart start_func;
void *context;
-
b
ool waitable;
+
SilcB
ool waitable;
} *SilcWin32Thread;
static DWORD silc_thread_tls;
} *SilcWin32Thread;
static DWORD silc_thread_tls;
@@
-44,15
+41,14
@@
unsigned __stdcall silc_thread_win32_start(void *context)
SilcWin32Thread thread = (SilcWin32Thread)context;
TlsSetValue(silc_thread_tls, 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,
return 0;
}
#endif
SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
-
b
ool waitable)
+
SilcB
ool waitable)
{
#ifdef SILC_THREADS
SilcWin32Thread thread;
{
#ifdef SILC_THREADS
SilcWin32Thread thread;
@@
-64,8
+60,10
@@
SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
thread->start_func = start_func;
thread->context = context;
thread->waitable = waitable;
thread->start_func = start_func;
thread->context = context;
thread->waitable = waitable;
- thread->thread = (HANDLE)_beginthreadex(NULL, 0, silc_thread_win32_start,
- (void *)thread, 0, &id);
+ thread->thread =
+ CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)silc_thread_win32_start,
+ (void *)thread, 0, &id);
+
if (!thread->thread) {
SILC_LOG_ERROR(("Could not create new thread"));
silc_free(thread);
if (!thread->thread) {
SILC_LOG_ERROR(("Could not create new thread"));
silc_free(thread);
@@
-89,14
+87,13
@@
void silc_thread_exit(void *exit_value)
/* If the thread is waitable the memory is freed only in silc_thread_wait
by another thread. If not waitable, free it now. */
if (!thread->waitable) {
/* If the thread is waitable the memory is freed only in silc_thread_wait
by another thread. If not waitable, free it now. */
if (!thread->waitable) {
-
CloseHandle(thread->thread
);
+
TerminateThread(thread->thread, 0
);
silc_free(thread);
}
TlsSetValue(silc_thread_tls, NULL);
}
silc_free(thread);
}
TlsSetValue(silc_thread_tls, NULL);
}
-
- _endthreadex(0);
+ ExitThread(0);
#endif
}
#endif
}
@@
-117,12
+114,12
@@
SilcThread silc_thread_self(void)
}
return (SilcThread)self;
}
return (SilcThread)self;
-#else
+
#else
return NULL;
#endif
}
return NULL;
#endif
}
-
b
ool silc_thread_wait(SilcThread thread, void **exit_value)
+
SilcB
ool silc_thread_wait(SilcThread thread, void **exit_value)
{
#ifdef SILC_THREADS
SilcWin32Thread self = (SilcWin32Thread)thread;
{
#ifdef SILC_THREADS
SilcWin32Thread self = (SilcWin32Thread)thread;
@@
-134,8
+131,9
@@
bool silc_thread_wait(SilcThread thread, void **exit_value)
/* The thread is waitable thus we will free all memory after the
WaitForSingleObject returns, the thread is destroyed after that. */
/* The thread is waitable thus we will free all memory after the
WaitForSingleObject returns, the thread is destroyed after that. */
- WaitForSingleObject(self->thread, INFINITE);
- CloseHandle(self->thread);
+ if (WaitForSingleObject(self->thread, 2500) == WAIT_TIMEOUT)
+ TerminateThread(self->thread, 0);
+
silc_free(self);
if (exit_value)
*exit_value = NULL;
silc_free(self);
if (exit_value)
*exit_value = NULL;