1 /* 2 * OpenBOR - http://www.chronocrash.com 3 * ----------------------------------------------------------------------- 4 * All rights reserved, see LICENSE in OpenBOR root for details. 5 * 6 * Copyright (c) 2004 - 2015 OpenBOR Team 7 */ 8 9 #ifndef THREADS_H 10 #define THREADS_H 11 12 #if WII 13 #include <ogcsys.h> 14 #include <ogc/cond.h> 15 struct bor_thread; 16 typedef struct bor_thread bor_thread; 17 typedef mutex_t bor_mutex; 18 typedef cond_t bor_cond; 19 #elif SDL 20 #include "SDL.h" 21 #include "SDL_thread.h" 22 typedef SDL_Thread bor_thread; 23 typedef SDL_mutex bor_mutex; 24 typedef SDL_cond bor_cond; 25 #else 26 #error threads not supported on this platform 27 #endif 28 29 // creates a new thread that returns when fn returns 30 bor_thread *thread_create(int (*fn)(void *), const char *name, void *data); 31 32 // waits for thread to finish 33 void thread_join(bor_thread *thread); 34 35 // create a mutex; returns NULL on error 36 bor_mutex *mutex_create(void); 37 38 // destroys a mutex 39 void mutex_destroy(bor_mutex *mutex); 40 41 // tries to lock a mutex; returns 0 on success and -1 on error 42 int mutex_lock(bor_mutex *mutex); 43 44 // unlocks a mutex; returns 0 on success and -1 on error 45 int mutex_unlock(bor_mutex *mutex); 46 47 // creates a new condition variable; returns NULL on error 48 bor_cond *cond_create(void); 49 50 // destroys and frees a condition variable 51 void cond_destroy(bor_cond *cond); 52 53 // signal a single thread waiting on this condition variable to wake up 54 int cond_signal(bor_cond *cond); 55 56 // broadcast to all threads waiting on this condition variable to wake up 57 int cond_broadcast(bor_cond *cond); 58 59 // make the current thread wait on the condition variable 60 // mutex must be locked; this function will unlock it when called and re-lock it before returning 61 int cond_wait(bor_cond *cond, bor_mutex *mutex); 62 63 // make the current thread wait on the condition variable with a timeout 64 // mutex must be locked; this function will unlock it when called and re-lock it before returning 65 int cond_wait_timed(bor_cond *cond, bor_mutex *mutex, int ms); 66 67 #endif // ifndef THREADS_H 68