Lines Matching defs:mutex
34 spinlock_t mutex;
37 /* Create a mutex */
40 SDL_mutex *mutex;
42 /* Allocate mutex memory */
43 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
44 if ( mutex ) {
45 spinlock_init(&mutex->mutex);
46 mutex->recursive = 0;
47 mutex->owner = 0;
51 return mutex;
54 /* Free the mutex */
55 void SDL_DestroyMutex(SDL_mutex *mutex)
57 if ( mutex ) {
58 SDL_free(mutex);
63 int SDL_mutexP(SDL_mutex *mutex)
70 if ( mutex == NULL ) {
71 SDL_SetError("Passed a NULL mutex");
76 if ( mutex->owner == this_thread ) {
77 ++mutex->recursive;
83 spinlock_lock(&mutex->mutex);
84 mutex->owner = this_thread;
85 mutex->recursive = 0;
92 /* Unlock the mutex */
93 int SDL_mutexV(SDL_mutex *mutex)
98 if ( mutex == NULL ) {
99 SDL_SetError("Passed a NULL mutex");
103 /* If we don't own the mutex, we can't unlock it */
104 if ( SDL_ThreadID() != mutex->owner ) {
105 SDL_SetError("mutex not owned by this thread");
109 if ( mutex->recursive ) {
110 --mutex->recursive;
114 the mutex and set the ownership before we reset it,
117 mutex->owner = 0;
118 spinlock_unlock(&mutex->mutex);