1  /*
2   * UAE - The Un*x Amiga Emulator
3   *
4   * Threading support, using SDL
5   *
6   * Copyright 1997, 2001 Bernd Schmidt
7   */
8 
9 #include <SDL.h>
10 #include <SDL_thread.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 typedef SDL_sem *uae_sem_t;
15 
uae_sem_init(uae_sem_t * PSEM,int DUMMY,int INIT)16 STATIC_INLINE int uae_sem_init(uae_sem_t *PSEM, int DUMMY, int INIT)
17 {
18    *PSEM = SDL_CreateSemaphore (INIT);
19 
20    return (*PSEM == 0);
21 }
22 #define uae_sem_destroy(PSEM)  SDL_DestroySemaphore (*PSEM)
23 #define uae_sem_post(PSEM)     SDL_SemPost (*PSEM)
24 #define uae_sem_wait(PSEM)     SDL_SemWait (*PSEM)
25 #define uae_sem_trywait(PSEM)  SDL_SemTryWait (*PSEM)
26 #define uae_sem_getvalue(PSEM) SDL_SemValue (*PSEM)
27 
28 #include "commpipe.h"
29 
30 typedef SDL_Thread *uae_thread_id;
31 
32 #define BAD_THREAD 0
33 
34 #define uae_set_thread_priority(pri)
35 
uae_start_thread(char * name,void * (* f)(void *),void * arg,uae_thread_id * tid)36 STATIC_INLINE int uae_start_thread (char *name, void *(*f) (void *), void *arg, uae_thread_id *tid)
37 {
38 	int result = 1;
39 
40 	*tid = SDL_CreateThread ((int (*)(void *))f, arg);
41 	if (*tid == NULL) {
42 		result = 0;
43 		write_log ("Thread '%s' failed to start!?\n", name ? name : "<unknown>");
44 	} else {
45 		write_log ("Thread '%s' started (%lu)\n", name, (size_t)(*tid) );
46 	}
47 
48 	return result;
49 }
50 
uae_wait_thread(uae_thread_id thread)51 STATIC_INLINE int uae_wait_thread (uae_thread_id thread)
52 {
53     SDL_WaitThread (thread, (int*)0);
54     return 0;
55 }
56 
uae_kill_thread(uae_thread_id * thread)57 STATIC_INLINE void uae_kill_thread (uae_thread_id* thread)
58 {
59 	SDL_KillThread(*thread);
60 	*thread = NULL;
61 }
62 
63 /* Do nothing; thread exits if thread function returns.  */
64 #define UAE_THREAD_EXIT do {} while (0)
65