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.
21 #include "silcincludes.h"
25 /* Thread structure for BeOS */
28 SilcThreadStart start_func;
33 /* Actual routine that is called by BeOS when the thread is created.
34 We will call the start_func from here. */
36 static void *silc_thread_beos_start(void *context)
38 SilcBeosThread thread = (SilcBeosThread)context;
39 return (*thread->start_func)(thread->context);
44 SilcThread silc_thread_create(SilcThreadStart start_func, void *context,
49 SilcBeosThread thread = silc_calloc(1, sizeof(*thread));
53 thread->start_func = start_func;
54 thread->context = context;
55 thread->waitable = waitable;
57 /* Create the thread, and run it */
58 thread->thread = spawn_thread((thread_func)silc_thread_beos_start,
59 B_NORMAL_PRIORITY, thread);
60 ret = resume_thread(thread->thread);
61 if (ret < B_NO_ERROR) {
62 SILC_LOG_ERROR(("Could not create new thread"));
67 return (SilcThread)thread->thread;
69 /* Call thread callback immediately */
70 (*start_func)(context);
75 void silc_thread_exit(void *exit_value)
78 exit_thread((status_t)exit_value);
82 SilcThread silc_thread_self(void)
85 return (SilcThread)find_thread(NULL);
91 bool silc_thread_wait(SilcThread thread, void **exit_value)
96 ret = wait_for_thread((thread_id)thread, &retval);
97 if (ret == B_NO_ERROR) {