diff options
Diffstat (limited to 'threading.c')
-rw-r--r-- | threading.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/threading.c b/threading.c new file mode 100644 index 00000000..c5d5a6c8 --- /dev/null +++ b/threading.c @@ -0,0 +1,27 @@ +#include <SDL/SDL.h> +#include <SDL/SDL_thread.h> +#include "threading.h" + +void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { + if (!SDL_CreateThread ((int (*)(void*))fn, (void*)ctx)) { + printf ("SDL_CreateThread failed!\n"); + } +} +uintptr_t mutex_create (void) { + SDL_mutex *mtx = SDL_CreateMutex (); + if (!mtx) { + printf ("SDL_CreateMutex failed!\n"); + } + return (uintptr_t)mtx; +} +void mutex_free (uintptr_t mtx) { + SDL_mutexP ((SDL_mutex*)mtx); // grant that no thread does processing now + SDL_DestroyMutex ((SDL_mutex*)mtx); +} +int mutex_lock (uintptr_t mtx) { + return SDL_mutexP ((SDL_mutex*)mtx); +} +int mutex_unlock (uintptr_t mtx) { + return SDL_mutexV ((SDL_mutex*)mtx); +} + |