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"
26 /* Thread structure for BeOS */
29 SilcThreadStart start_func;
34 /* Actual routine that is called by BeOS when the thread is created.
35 We will call the start_func from here. */
37 static void *silc_thread_beos_start(void *context)
39 SilcBeosThread thread = (SilcBeosThread)context;
40 return (*thread->start_func)(thread->context);
45 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
50 SilcBeosThread thread = silc_calloc(1, sizeof(*thread));
54 thread->start_func = start_func;
55 thread->context = context;
56 thread->waitable = waitable;
58 /* Create the thread, and run it */
59 thread->thread = spawn_thread((thread_func)silc_thread_beos_start,
60 B_NORMAL_PRIORITY, thread);
61 ret = resume_thread(thread->thread);
62 if (ret < B_NO_ERROR) {
63 SILC_LOG_ERROR(("Could not create new thread"));
68 return (SilcThread)thread->thread;
70 /* Call thread callback immediately */
71 (*start_func)(context);
76 void silc_thread_exit(void *exit_value)
79 exit_thread((status_t)exit_value);
83 SilcThread silc_thread_self(void)
86 return (SilcThread)find_thread(NULL);
92 bool silc_thread_wait(SilcThread thread, void **exit_value)
97 ret = wait_for_thread((thread_id)thread, &retval);
98 if (ret == B_NO_ERROR) {
100 *exit_value = retval;