summaryrefslogtreecommitdiff
path: root/threading.c
blob: c5d5a6c867bd0205d57fc3f10d38464b9e626a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
}