Lines Matching defs:mutex
44 SDL_mutex *mutex;
48 mutex = (SDL_mutex *)SDL_calloc(1, sizeof(*mutex));
49 if ( mutex ) {
56 if ( pthread_mutex_init(&mutex->id, &attr) != 0 ) {
58 SDL_free(mutex);
59 mutex = NULL;
64 return(mutex);
67 void SDL_DestroyMutex(SDL_mutex *mutex)
69 if ( mutex ) {
70 pthread_mutex_destroy(&mutex->id);
71 SDL_free(mutex);
75 /* Lock the mutex */
76 int SDL_mutexP(SDL_mutex *mutex)
83 if ( mutex == NULL ) {
84 SDL_SetError("Passed a NULL mutex");
91 if ( mutex->owner == this_thread ) {
92 ++mutex->recursive;
98 if ( pthread_mutex_lock(&mutex->id) == 0 ) {
99 mutex->owner = this_thread;
100 mutex->recursive = 0;
107 if ( pthread_mutex_lock(&mutex->id) < 0 ) {
115 int SDL_mutexV(SDL_mutex *mutex)
119 if ( mutex == NULL ) {
120 SDL_SetError("Passed a NULL mutex");
126 /* We can only unlock the mutex if we own it */
127 if ( pthread_self() == mutex->owner ) {
128 if ( mutex->recursive ) {
129 --mutex->recursive;
133 the mutex and set the ownership before we reset it,
136 mutex->owner = 0;
137 pthread_mutex_unlock(&mutex->id);
140 SDL_SetError("mutex not owned by this thread");
145 if ( pthread_mutex_unlock(&mutex->id) < 0 ) {