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

Commit

Permalink
Changed the name of SDL_mutexP() SDL_mutexV()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 8, 2013
1 parent 76340ab commit 9a1385b
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions include/SDL_mutex.h
Expand Up @@ -70,8 +70,8 @@ extern DECLSPEC SDL_mutex *SDLCALL SDL_CreateMutex(void);
*
* \return 0, or -1 on error.
*/
#define SDL_LockMutex(m) SDL_mutexP(m)
extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
#define SDL_mutexP(m) SDL_LockMutex(m)
extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex);

/**
* Try to lock the mutex
Expand All @@ -88,8 +88,8 @@ extern DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_mutex * mutex);
* \warning It is an error to unlock a mutex that has not been locked by
* the current thread, and doing so results in undefined behavior.
*/
#define SDL_UnlockMutex(m) SDL_mutexV(m)
extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
#define SDL_mutexV(m) SDL_UnlockMutex(m)
extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex);

/**
* Destroy a mutex.
Expand Down
6 changes: 3 additions & 3 deletions src/atomic/SDL_spinlock.c
Expand Up @@ -41,13 +41,13 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
/* Race condition on first lock... */
_spinlock_mutex = SDL_CreateMutex();
}
SDL_mutexP(_spinlock_mutex);
SDL_LockMutex(_spinlock_mutex);
if (*lock == 0) {
*lock = 1;
SDL_mutexV(_spinlock_mutex);
SDL_UnlockMutex(_spinlock_mutex);
return SDL_TRUE;
} else {
SDL_mutexV(_spinlock_mutex);
SDL_UnlockMutex(_spinlock_mutex);
return SDL_FALSE;
}

Expand Down
12 changes: 6 additions & 6 deletions src/audio/SDL_audio.c
Expand Up @@ -200,7 +200,7 @@ SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
if (device->thread && (SDL_ThreadID() == device->threadid)) {
return;
}
SDL_mutexP(device->mixer_lock);
SDL_LockMutex(device->mixer_lock);
}

static void
Expand All @@ -209,7 +209,7 @@ SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
if (device->thread && (SDL_ThreadID() == device->threadid)) {
return;
}
SDL_mutexV(device->mixer_lock);
SDL_UnlockMutex(device->mixer_lock);
}


Expand Down Expand Up @@ -407,9 +407,9 @@ SDL_RunAudio(void *devicep)
}

/* Read from the callback into the _input_ stream */
SDL_mutexP(device->mixer_lock);
SDL_LockMutex(device->mixer_lock);
(*fill) (udata, istream, istream_len);
SDL_mutexV(device->mixer_lock);
SDL_UnlockMutex(device->mixer_lock);

/* Convert the audio if necessary and write to the streamer */
if (device->convert.needed) {
Expand Down Expand Up @@ -480,9 +480,9 @@ SDL_RunAudio(void *devicep)
}
}

SDL_mutexP(device->mixer_lock);
SDL_LockMutex(device->mixer_lock);
(*fill) (udata, stream, stream_len);
SDL_mutexV(device->mixer_lock);
SDL_UnlockMutex(device->mixer_lock);

/* Convert the audio if necessary */
if (device->convert.needed) {
Expand Down
8 changes: 4 additions & 4 deletions src/audio/baudio/SDL_beaudio.cc
Expand Up @@ -54,18 +54,18 @@ FillSound(void *device, void *stream, size_t len,

if (!audio->paused) {
if (audio->convert.needed) {
SDL_mutexP(audio->mixer_lock);
SDL_LockMutex(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) audio->convert.buf,
audio->convert.len);
SDL_mutexV(audio->mixer_lock);
SDL_UnlockMutex(audio->mixer_lock);
SDL_ConvertAudio(&audio->convert);
SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
} else {
SDL_mutexP(audio->mixer_lock);
SDL_LockMutex(audio->mixer_lock);
(*audio->spec.callback) (audio->spec.userdata,
(Uint8 *) stream, len);
SDL_mutexV(audio->mixer_lock);
SDL_UnlockMutex(audio->mixer_lock);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/audio/coreaudio/SDL_coreaudio.c
Expand Up @@ -280,10 +280,10 @@ outputCallback(void *inRefCon,
while (remaining > 0) {
if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
/* Generate the data */
SDL_mutexP(this->mixer_lock);
SDL_LockMutex(this->mixer_lock);
(*this->spec.callback)(this->spec.userdata,
this->hidden->buffer, this->hidden->bufferSize);
SDL_mutexV(this->mixer_lock);
SDL_UnlockMutex(this->mixer_lock);
this->hidden->bufferOffset = 0;
}

Expand Down
12 changes: 6 additions & 6 deletions src/events/SDL_events.c
Expand Up @@ -212,7 +212,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
}
/* Lock the event queue */
used = 0;
if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) {
if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
if (action == SDL_ADDEVENT) {
for (i = 0; i < numevents; ++i) {
used += SDL_AddEvent(&events[i]);
Expand Down Expand Up @@ -242,7 +242,7 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
}
}
}
SDL_mutexV(SDL_EventQ.lock);
SDL_UnlockMutex(SDL_EventQ.lock);
} else {
SDL_SetError("Couldn't lock event queue");
used = -1;
Expand Down Expand Up @@ -285,7 +285,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType)
#endif

/* Lock the event queue */
if (SDL_mutexP(SDL_EventQ.lock) == 0) {
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
int spot = SDL_EventQ.head;
while (spot != SDL_EventQ.tail) {
Uint32 type = SDL_EventQ.event[spot].type;
Expand All @@ -295,7 +295,7 @@ SDL_FlushEvents(Uint32 minType, Uint32 maxType)
spot = (spot + 1) % MAXEVENTS;
}
}
SDL_mutexV(SDL_EventQ.lock);
SDL_UnlockMutex(SDL_EventQ.lock);
}
}

Expand Down Expand Up @@ -446,7 +446,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
void
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
{
if (SDL_mutexP(SDL_EventQ.lock) == 0) {
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
int spot;

spot = SDL_EventQ.head;
Expand All @@ -458,7 +458,7 @@ SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
}
}
}
SDL_mutexV(SDL_EventQ.lock);
SDL_UnlockMutex(SDL_EventQ.lock);
}

Uint8
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/windows/SDL_dxjoystick.c
Expand Up @@ -819,7 +819,7 @@ void SDL_SYS_JoystickDetect()
pCurList = SYS_Joystick;
SYS_Joystick = NULL;
s_iNewGUID = 0;
SDL_mutexP( s_mutexJoyStickEnum );
SDL_LockMutex( s_mutexJoyStickEnum );

if ( !s_pKnownJoystickGUIDs )
s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS );
Expand All @@ -832,7 +832,7 @@ void SDL_SYS_JoystickDetect()
EnumJoysticksCallback,
&pCurList, DIEDFL_ATTACHEDONLY);

SDL_mutexV( s_mutexJoyStickEnum );
SDL_UnlockMutex( s_mutexJoyStickEnum );
}

if ( pCurList )
Expand Down
6 changes: 3 additions & 3 deletions src/thread/SDL_thread.c
Expand Up @@ -85,7 +85,7 @@ SDL_AddThread(SDL_Thread * thread)
return;
}
}
SDL_mutexP(thread_lock);
SDL_LockMutex(thread_lock);

/* Expand the list of threads, if necessary */
#ifdef DEBUG_THREADS
Expand Down Expand Up @@ -118,7 +118,7 @@ SDL_DelThread(SDL_Thread * thread)
if (!thread_lock) {
return;
}
SDL_mutexP(thread_lock);
SDL_LockMutex(thread_lock);
for (i = 0; i < SDL_numthreads; ++i) {
if (thread == SDL_Threads[i]) {
break;
Expand Down Expand Up @@ -164,7 +164,7 @@ SDL_GetErrBuf(void)
SDL_threadID this_thread;

this_thread = SDL_ThreadID();
SDL_mutexP(thread_lock);
SDL_LockMutex(thread_lock);
for (i = 0; i < SDL_numthreads; ++i) {
if (this_thread == SDL_Threads[i]->threadid) {
errbuf = &SDL_Threads[i]->errbuf;
Expand Down
2 changes: 1 addition & 1 deletion src/thread/generic/SDL_sysmutex.c
Expand Up @@ -70,7 +70,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)

/* Lock the mutex */
int
SDL_mutexP(SDL_mutex * mutex)
SDL_LockMutex(SDL_mutex * mutex)
{
#if SDL_THREADS_DISABLED
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/thread/generic/SDL_syssem.c
Expand Up @@ -123,8 +123,8 @@ SDL_DestroySemaphore(SDL_sem * sem)
}
SDL_DestroyCond(sem->count_nonzero);
if (sem->count_lock) {
SDL_mutexP(sem->count_lock);
SDL_mutexV(sem->count_lock);
SDL_LockMutex(sem->count_lock);
SDL_UnlockMutex(sem->count_lock);
SDL_DestroyMutex(sem->count_lock);
}
SDL_free(sem);
Expand Down
4 changes: 2 additions & 2 deletions src/thread/nds/SDL_sysmutex.c
Expand Up @@ -78,7 +78,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)

/* Lock the mutex */
int
SDL_mutexP(SDL_mutex * mutex)
SDL_LockMutex(SDL_mutex * mutex)
{
#ifdef DISABLE_THREADS
return 0;
Expand Down Expand Up @@ -143,7 +143,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)

/* Unlock the mutex */
int
SDL_mutexV(SDL_mutex * mutex)
SDL_UnlockMutex(SDL_mutex * mutex)
{
#ifdef DISABLE_THREADS
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/thread/nds/SDL_syssem.c
Expand Up @@ -129,8 +129,8 @@ SDL_DestroySemaphore(SDL_sem * sem)
SDL_Delay(10);
}
SDL_DestroyCond(sem->count_nonzero);
SDL_mutexP(sem->count_lock);
SDL_mutexV(sem->count_lock);
SDL_LockMutex(sem->count_lock);
SDL_UnlockMutex(sem->count_lock);
SDL_DestroyMutex(sem->count_lock);
free(sem);
}
Expand Down
4 changes: 2 additions & 2 deletions src/thread/pthread/SDL_sysmutex.c
Expand Up @@ -79,7 +79,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)

/* Lock the mutex */
int
SDL_mutexP(SDL_mutex * mutex)
SDL_LockMutex(SDL_mutex * mutex)
{
int retval;
#if FAKE_RECURSIVE_MUTEX
Expand Down Expand Up @@ -165,7 +165,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
}

int
SDL_mutexV(SDL_mutex * mutex)
SDL_UnlockMutex(SDL_mutex * mutex)
{
int retval;

Expand Down
4 changes: 2 additions & 2 deletions src/thread/windows/SDL_sysmutex.c
Expand Up @@ -64,7 +64,7 @@ SDL_DestroyMutex(SDL_mutex * mutex)

/* Lock the mutex */
int
SDL_mutexP(SDL_mutex * mutex)
SDL_LockMutex(SDL_mutex * mutex)
{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
Expand Down Expand Up @@ -93,7 +93,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)

/* Unlock the mutex */
int
SDL_mutexV(SDL_mutex * mutex)
SDL_UnlockMutex(SDL_mutex * mutex)
{
if (mutex == NULL) {
SDL_SetError("Passed a NULL mutex");
Expand Down
8 changes: 4 additions & 4 deletions src/timer/SDL_timer.c
Expand Up @@ -334,10 +334,10 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
entry->timer = timer;
entry->timerID = timer->timerID;

SDL_mutexP(data->timermap_lock);
SDL_LockMutex(data->timermap_lock);
entry->next = data->timermap;
data->timermap = entry;
SDL_mutexV(data->timermap_lock);
SDL_UnlockMutex(data->timermap_lock);

/* Add the timer to the pending list for the timer thread */
SDL_AtomicLock(&data->lock);
Expand All @@ -359,7 +359,7 @@ SDL_RemoveTimer(SDL_TimerID id)
SDL_bool canceled = SDL_FALSE;

/* Find the timer */
SDL_mutexP(data->timermap_lock);
SDL_LockMutex(data->timermap_lock);
prev = NULL;
for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
if (entry->timerID == id) {
Expand All @@ -371,7 +371,7 @@ SDL_RemoveTimer(SDL_TimerID id)
break;
}
}
SDL_mutexV(data->timermap_lock);
SDL_UnlockMutex(data->timermap_lock);

if (entry) {
if (!entry->timer->canceled) {
Expand Down
8 changes: 4 additions & 4 deletions test/testatomic.c
Expand Up @@ -412,7 +412,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event
int delta;
SDL_bool status = SDL_FALSE;

SDL_mutexP(queue->mutex);
SDL_LockMutex(queue->mutex);

queue_pos = (unsigned)queue->enqueue_pos.value;
entry = &queue->entries[queue_pos & WRAP_MASK];
Expand All @@ -432,7 +432,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event
printf("ERROR: mutex failed!\n");
}

SDL_mutexV(queue->mutex);
SDL_UnlockMutex(queue->mutex);

return status;
}
Expand All @@ -445,7 +445,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
int delta;
SDL_bool status = SDL_FALSE;

SDL_mutexP(queue->mutex);
SDL_LockMutex(queue->mutex);

queue_pos = (unsigned)queue->dequeue_pos.value;
entry = &queue->entries[queue_pos & WRAP_MASK];
Expand All @@ -465,7 +465,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
printf("ERROR: mutex failed!\n");
}

SDL_mutexV(queue->mutex);
SDL_UnlockMutex(queue->mutex);

return status;
}
Expand Down
4 changes: 2 additions & 2 deletions test/testlock.c
Expand Up @@ -69,14 +69,14 @@ Run(void *data)
signal(SIGTERM, closemutex);
while (!doterminate) {
printf("Process %lu ready to work\n", SDL_ThreadID());
if (SDL_mutexP(mutex) < 0) {
if (SDL_LockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
exit(1);
}
printf("Process %lu, working!\n", SDL_ThreadID());
SDL_Delay(1 * 1000);
printf("Process %lu, done!\n", SDL_ThreadID());
if (SDL_mutexV(mutex) < 0) {
if (SDL_UnlockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
exit(1);
}
Expand Down

0 comments on commit 9a1385b

Please sign in to comment.