Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Fix mutex ownership in pthread SDL_CondWait() #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/thread/pthread/SDL_syscond.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
default:
retval = SDL_SetError("pthread_cond_timedwait() failed");
}
#if FAKE_RECURSIVE_MUTEX
mutex->owner = pthread_self();
mutex->recursive = 0;
#endif
return retval;
}

Expand All @@ -152,6 +156,10 @@ SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
} else if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
return SDL_SetError("pthread_cond_wait() failed");
}
#if FAKE_RECURSIVE_MUTEX
mutex->owner = pthread_self();
mutex->recursive = 0;
#endif
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions src/thread/pthread/SDL_sysmutex_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@
#ifndef SDL_mutex_c_h_
#define SDL_mutex_c_h_

#if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && \
!SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
#define FAKE_RECURSIVE_MUTEX 1
#endif

struct SDL_mutex
{
pthread_mutex_t id;
#if FAKE_RECURSIVE_MUTEX
int recursive;
pthread_t owner;
#endif
};

#endif /* SDL_mutex_c_h_ */
Expand Down