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 /* XXX This leaks memory. Perhaps the SilcThread API should be changed
23 since the silc_thread_self() causes that BeOS and OS/2 is hard to
24 do to support this SilcThread API */
30 /* Thread structure for BeOS */
33 SilcThreadStart start_func;
38 /* Actual routine that is called by BeOS when the thread is created.
39 We will call the start_func from here. */
41 static void *silc_thread_beos_start(void *context)
43 SilcBeosThread thread = (SilcBeosThread)context;
44 return (*thread->start_func)(thread->context);
49 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
54 SilcBeosThread thread = silc_calloc(1, sizeof(*thread));
58 thread->start_func = start_func;
59 thread->context = context;
60 thread->waitable = waitable;
62 /* Create the thread, and run it */
63 thread->thread = spawn_thread((thread_func)silc_thread_beos_start,
64 B_NORMAL_PRIORITY, thread);
65 ret = resume_thread(thread->thread);
66 if (ret < B_NO_ERROR) {
67 SILC_LOG_ERROR(("Could not create new thread"));
72 return (SilcThread)thread->thread;
74 /* Call thread callback immediately */
75 (*start_func)(context);
80 void silc_thread_exit(void *exit_value)
83 exit_thread((status_t)exit_value);
87 SilcThread silc_thread_self(void)
90 return (SilcThread)find_thread(NULL);
96 SilcBool silc_thread_wait(SilcThread thread, void **exit_value)
101 ret = wait_for_thread((thread_id)thread, &retval);
102 if (ret == B_NO_ERROR) {
104 *exit_value = retval;