1  /*
2   * UAE - The Un*x Amiga Emulator
3   *
4   * Threading support for BeOS
5   *
6   * Copyright 2004 Richard Drummond
7   *
8   * Based on Axel Doerfler's BeUAE implementation.
9   */
10 #include <OS.h>
11 
12 /* Sempahores. We use POSIX semaphores; if you are porting this to a machine
13  * with different ones, make them look like POSIX semaphores. */
14 
15 typedef sem_id uae_sem_t;
16 
uae_sem_init(uae_sem_t * PSEM,int DUMMY,int INIT)17 STATIC_INLINE int uae_sem_init (uae_sem_t *PSEM, int DUMMY, int INIT)
18 {
19     *PSEM = create_sem (INIT, "uae");
20     return *PSEM != 0;
21 }
22 
23 #define uae_sem_destroy(PSEM)  delete_sem  (*PSEM)
24 #define uae_sem_post(PSEM)     release_sem (*PSEM)
25 #define uae_sem_wait(PSEM)     acquire_sem (*PSEM)
26 #define uae_sem_trywait(PSEM)  acquire_sem_etc (*PSEM, 1, B_RELATIVE_TIMEOUT, 0)
27 
28 /* Possibly dodgy? Check whether this fn is even needed */
29 #define uae_sem_getvalue(PSEM) get_sem_count (*PSEM)
30 
31 #include "commpipe.h"
32 
33 typedef thread_id uae_thread_id;
34 
35 #define BAD_THREAD 0
36 
37 
uae_start_thread(char * name,void * (* f)(void *),void * arg,uae_thread_id * thread)38 STATIC_INLINE int uae_start_thread (char *name, void *(*f) (void *), void *arg, uae_thread_id *thread)
39 {
40     *thread = spawn_thread ((thread_func)f, "uae thread",
41 			    B_NORMAL_PRIORITY, arg);
42     resume_thread (*thread);
43     return *thread <= 0;
44 }
45 
uae_wait_thread(uae_thread_id thread)46 STATIC_INLINE int uae_wait_thread (uae_thread_id thread)
47 {
48     status_t dummy_return;
49     wait_for_thread (thread, &dummy_return);
50     return 0;
51 }
52 
53 /* Do nothing; thread exits if thread function returns.  */
54 #define UAE_THREAD_EXIT exit_thread (0)
55 
56 #define uae_set_thread_priority(pri) /* todo */
57