diff options
author | waker <wakeroid@gmail.com> | 2009-07-04 03:56:35 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2009-07-04 03:56:35 +0200 |
commit | 516186b494d00c5dcb27f3f83cd8b9b7abbd6f46 (patch) | |
tree | 29fec73b5cc66e4bbd22bc55fc91a2e2af352dc1 /threading.c | |
parent | 6f16e4e363936722d7f3c3b819f787e947260310 (diff) |
added separate thread for sdl stuff, to be able to pass messages
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); +} + |