5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2002 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
19 /* I used Apache's APR code as a reference here. */
22 #include "silcincludes.h"
24 /* XXX This leaks memory. Perhaps the SilcThread API should be changed
25 since the silc_thread_self() causes that BeOS and OS/2 is hard to
26 do to support this SilcThread API */
30 /* Thread structure for OS/2 */
33 SilcThreadStart start_func;
38 /* Actual routine that is called by OS/2 when the thread is created.
39 We will call the start_func from here. When this returns the thread
42 static void silc_thread_os2_start(void *context)
44 SilcOs2Thread thread = (SilcOs2Thread)context;
45 silc_thread_exit((*thread->start_func)(thread->context));
50 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
55 SilcOs2Thread thread = silc_calloc(1, sizeof(*thread));
59 thread->start_func = start_func;
60 thread->context = context;
61 thread->waitable = waitable;
63 /* Create the thread, and run it */
64 thread->thread = _beginthread(silc_thread_os2_start, NULL, 65536, thread);
65 if (thread->thread < 0) {
66 SILC_LOG_ERROR(("Could not create new thread"));
71 return (SilcThread)thread->thread;
73 /* Call thread callback immediately */
74 (*start_func)(context);
79 void silc_thread_exit(void *exit_value)
86 SilcThread silc_thread_self(void)
91 DosGetInfoBlocks(&tib, &pib);
92 return (SilcThread)tib->tib_ptib2->tib2_ultid;
98 SilcBool silc_thread_wait(SilcThread thread, void **exit_value)
102 if (DosWaitThread((unsigned long)thread, DCWW_WAIT) !=
103 ERROR_INVALID_THREADID) {