Home | History | Annotate | Download | only in generic

Lines Matching defs:mutex

36 /* Create a mutex */
39 SDL_mutex *mutex;
41 /* Allocate mutex memory */
42 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
43 if ( mutex ) {
44 /* Create the mutex semaphore, with initial value 1 */
45 mutex->sem = SDL_CreateSemaphore(1);
46 mutex->recursive = 0;
47 mutex->owner = 0;
48 if ( ! mutex->sem ) {
49 SDL_free(mutex);
50 mutex = NULL;
55 return mutex;
58 /* Free the mutex */
59 void SDL_DestroyMutex(SDL_mutex *mutex)
61 if ( mutex ) {
62 if ( mutex->sem ) {
63 SDL_DestroySemaphore(mutex->sem);
65 SDL_free(mutex);
70 int SDL_mutexP(SDL_mutex *mutex)
77 if ( mutex == NULL ) {
78 SDL_SetError("Passed a NULL mutex");
83 if ( mutex->owner == this_thread ) {
84 ++mutex->recursive;
90 SDL_SemWait(mutex->sem);
91 mutex->owner = this_thread;
92 mutex->recursive = 0;
99 /* Unlock the mutex */
100 int SDL_mutexV(SDL_mutex *mutex)
105 if ( mutex == NULL ) {
106 SDL_SetError("Passed a NULL mutex");
110 /* If we don't own the mutex, we can't unlock it */
111 if ( SDL_ThreadID() != mutex->owner ) {
112 SDL_SetError("mutex not owned by this thread");
116 if ( mutex->recursive ) {
117 --mutex->recursive;
121 the mutex and set the ownership before we reset it,
124 mutex->owner = 0;
125 SDL_SemPost(mutex->sem);