Changed the name of SDL_mutexP() SDL_mutexV()
authorSam Lantinga <slouken@libsdl.org>
Thu, 07 Mar 2013 20:12:40 -0800
changeset 6977b73d51026c68
parent 6976 177d1dc3dba6
child 6978 e851407e9294
Changed the name of SDL_mutexP() SDL_mutexV()
include/SDL_mutex.h
src/atomic/SDL_spinlock.c
src/audio/SDL_audio.c
src/audio/baudio/SDL_beaudio.cc
src/audio/coreaudio/SDL_coreaudio.c
src/events/SDL_events.c
src/joystick/windows/SDL_dxjoystick.c
src/thread/SDL_thread.c
src/thread/generic/SDL_sysmutex.c
src/thread/generic/SDL_syssem.c
src/thread/nds/SDL_sysmutex.c
src/thread/nds/SDL_syssem.c
src/thread/pthread/SDL_sysmutex.c
src/thread/windows/SDL_sysmutex.c
src/timer/SDL_timer.c
test/testatomic.c
test/testlock.c
     1.1 --- a/include/SDL_mutex.h	Thu Mar 07 15:37:08 2013 -0800
     1.2 +++ b/include/SDL_mutex.h	Thu Mar 07 20:12:40 2013 -0800
     1.3 @@ -70,8 +70,8 @@
     1.4   *  
     1.5   *  \return 0, or -1 on error.
     1.6   */
     1.7 -#define SDL_LockMutex(m)	SDL_mutexP(m)
     1.8 -extern DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex * mutex);
     1.9 +#define SDL_mutexP(m)	SDL_LockMutex(m)
    1.10 +extern DECLSPEC int SDLCALL SDL_LockMutex(SDL_mutex * mutex);
    1.11  
    1.12  /**
    1.13   *  Try to lock the mutex
    1.14 @@ -88,8 +88,8 @@
    1.15   *  \warning It is an error to unlock a mutex that has not been locked by
    1.16   *           the current thread, and doing so results in undefined behavior.
    1.17   */
    1.18 -#define SDL_UnlockMutex(m)	SDL_mutexV(m)
    1.19 -extern DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex * mutex);
    1.20 +#define SDL_mutexV(m)	SDL_UnlockMutex(m)
    1.21 +extern DECLSPEC int SDLCALL SDL_UnlockMutex(SDL_mutex * mutex);
    1.22  
    1.23  /** 
    1.24   *  Destroy a mutex.
     2.1 --- a/src/atomic/SDL_spinlock.c	Thu Mar 07 15:37:08 2013 -0800
     2.2 +++ b/src/atomic/SDL_spinlock.c	Thu Mar 07 20:12:40 2013 -0800
     2.3 @@ -41,13 +41,13 @@
     2.4          /* Race condition on first lock... */
     2.5          _spinlock_mutex = SDL_CreateMutex();
     2.6      }
     2.7 -    SDL_mutexP(_spinlock_mutex);
     2.8 +    SDL_LockMutex(_spinlock_mutex);
     2.9      if (*lock == 0) {
    2.10          *lock = 1;
    2.11 -        SDL_mutexV(_spinlock_mutex);
    2.12 +        SDL_UnlockMutex(_spinlock_mutex);
    2.13          return SDL_TRUE;
    2.14      } else {
    2.15 -        SDL_mutexV(_spinlock_mutex);
    2.16 +        SDL_UnlockMutex(_spinlock_mutex);
    2.17          return SDL_FALSE;
    2.18      }
    2.19  
     3.1 --- a/src/audio/SDL_audio.c	Thu Mar 07 15:37:08 2013 -0800
     3.2 +++ b/src/audio/SDL_audio.c	Thu Mar 07 20:12:40 2013 -0800
     3.3 @@ -200,7 +200,7 @@
     3.4      if (device->thread && (SDL_ThreadID() == device->threadid)) {
     3.5          return;
     3.6      }
     3.7 -    SDL_mutexP(device->mixer_lock);
     3.8 +    SDL_LockMutex(device->mixer_lock);
     3.9  }
    3.10  
    3.11  static void
    3.12 @@ -209,7 +209,7 @@
    3.13      if (device->thread && (SDL_ThreadID() == device->threadid)) {
    3.14          return;
    3.15      }
    3.16 -    SDL_mutexV(device->mixer_lock);
    3.17 +    SDL_UnlockMutex(device->mixer_lock);
    3.18  }
    3.19  
    3.20  
    3.21 @@ -407,9 +407,9 @@
    3.22                  }
    3.23  
    3.24                  /* Read from the callback into the _input_ stream */
    3.25 -                SDL_mutexP(device->mixer_lock);
    3.26 +                SDL_LockMutex(device->mixer_lock);
    3.27                  (*fill) (udata, istream, istream_len);
    3.28 -                SDL_mutexV(device->mixer_lock);
    3.29 +                SDL_UnlockMutex(device->mixer_lock);
    3.30  
    3.31                  /* Convert the audio if necessary and write to the streamer */
    3.32                  if (device->convert.needed) {
    3.33 @@ -480,9 +480,9 @@
    3.34                  }
    3.35              }
    3.36  
    3.37 -            SDL_mutexP(device->mixer_lock);
    3.38 +            SDL_LockMutex(device->mixer_lock);
    3.39              (*fill) (udata, stream, stream_len);
    3.40 -            SDL_mutexV(device->mixer_lock);
    3.41 +            SDL_UnlockMutex(device->mixer_lock);
    3.42  
    3.43              /* Convert the audio if necessary */
    3.44              if (device->convert.needed) {
     4.1 --- a/src/audio/baudio/SDL_beaudio.cc	Thu Mar 07 15:37:08 2013 -0800
     4.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Thu Mar 07 20:12:40 2013 -0800
     4.3 @@ -54,18 +54,18 @@
     4.4  
     4.5      if (!audio->paused) {
     4.6          if (audio->convert.needed) {
     4.7 -            SDL_mutexP(audio->mixer_lock);
     4.8 +            SDL_LockMutex(audio->mixer_lock);
     4.9              (*audio->spec.callback) (audio->spec.userdata,
    4.10                                       (Uint8 *) audio->convert.buf,
    4.11                                       audio->convert.len);
    4.12 -            SDL_mutexV(audio->mixer_lock);
    4.13 +            SDL_UnlockMutex(audio->mixer_lock);
    4.14              SDL_ConvertAudio(&audio->convert);
    4.15              SDL_memcpy(stream, audio->convert.buf, audio->convert.len_cvt);
    4.16          } else {
    4.17 -            SDL_mutexP(audio->mixer_lock);
    4.18 +            SDL_LockMutex(audio->mixer_lock);
    4.19              (*audio->spec.callback) (audio->spec.userdata,
    4.20                                       (Uint8 *) stream, len);
    4.21 -            SDL_mutexV(audio->mixer_lock);
    4.22 +            SDL_UnlockMutex(audio->mixer_lock);
    4.23          }
    4.24      }
    4.25  }
     5.1 --- a/src/audio/coreaudio/SDL_coreaudio.c	Thu Mar 07 15:37:08 2013 -0800
     5.2 +++ b/src/audio/coreaudio/SDL_coreaudio.c	Thu Mar 07 20:12:40 2013 -0800
     5.3 @@ -280,10 +280,10 @@
     5.4          while (remaining > 0) {
     5.5              if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
     5.6                  /* Generate the data */
     5.7 -                SDL_mutexP(this->mixer_lock);
     5.8 +                SDL_LockMutex(this->mixer_lock);
     5.9                  (*this->spec.callback)(this->spec.userdata,
    5.10                              this->hidden->buffer, this->hidden->bufferSize);
    5.11 -                SDL_mutexV(this->mixer_lock);
    5.12 +                SDL_UnlockMutex(this->mixer_lock);
    5.13                  this->hidden->bufferOffset = 0;
    5.14              }
    5.15  
     6.1 --- a/src/events/SDL_events.c	Thu Mar 07 15:37:08 2013 -0800
     6.2 +++ b/src/events/SDL_events.c	Thu Mar 07 20:12:40 2013 -0800
     6.3 @@ -212,7 +212,7 @@
     6.4      }
     6.5      /* Lock the event queue */
     6.6      used = 0;
     6.7 -    if (!SDL_EventQ.lock || SDL_mutexP(SDL_EventQ.lock) == 0) {
     6.8 +    if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
     6.9          if (action == SDL_ADDEVENT) {
    6.10              for (i = 0; i < numevents; ++i) {
    6.11                  used += SDL_AddEvent(&events[i]);
    6.12 @@ -242,7 +242,7 @@
    6.13                  }
    6.14              }
    6.15          }
    6.16 -        SDL_mutexV(SDL_EventQ.lock);
    6.17 +        SDL_UnlockMutex(SDL_EventQ.lock);
    6.18      } else {
    6.19          SDL_SetError("Couldn't lock event queue");
    6.20          used = -1;
    6.21 @@ -285,7 +285,7 @@
    6.22  #endif
    6.23  
    6.24      /* Lock the event queue */
    6.25 -    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
    6.26 +    if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
    6.27          int spot = SDL_EventQ.head;
    6.28          while (spot != SDL_EventQ.tail) {
    6.29              Uint32 type = SDL_EventQ.event[spot].type;
    6.30 @@ -295,7 +295,7 @@
    6.31                  spot = (spot + 1) % MAXEVENTS;
    6.32              }
    6.33          }
    6.34 -        SDL_mutexV(SDL_EventQ.lock);
    6.35 +        SDL_UnlockMutex(SDL_EventQ.lock);
    6.36      }
    6.37  }
    6.38  
    6.39 @@ -446,7 +446,7 @@
    6.40  void
    6.41  SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
    6.42  {
    6.43 -    if (SDL_mutexP(SDL_EventQ.lock) == 0) {
    6.44 +    if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
    6.45          int spot;
    6.46  
    6.47          spot = SDL_EventQ.head;
    6.48 @@ -458,7 +458,7 @@
    6.49              }
    6.50          }
    6.51      }
    6.52 -    SDL_mutexV(SDL_EventQ.lock);
    6.53 +    SDL_UnlockMutex(SDL_EventQ.lock);
    6.54  }
    6.55  
    6.56  Uint8
     7.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Thu Mar 07 15:37:08 2013 -0800
     7.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Thu Mar 07 20:12:40 2013 -0800
     7.3 @@ -819,7 +819,7 @@
     7.4  		pCurList = SYS_Joystick;
     7.5  		SYS_Joystick = NULL;
     7.6  		s_iNewGUID = 0;
     7.7 -		SDL_mutexP( s_mutexJoyStickEnum );
     7.8 +		SDL_LockMutex( s_mutexJoyStickEnum );
     7.9  
    7.10  		if ( !s_pKnownJoystickGUIDs )
    7.11  			s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS );
    7.12 @@ -832,7 +832,7 @@
    7.13  			EnumJoysticksCallback,
    7.14  			&pCurList, DIEDFL_ATTACHEDONLY);
    7.15  
    7.16 -		SDL_mutexV( s_mutexJoyStickEnum );
    7.17 +		SDL_UnlockMutex( s_mutexJoyStickEnum );
    7.18  	}
    7.19  
    7.20  	if ( pCurList )
     8.1 --- a/src/thread/SDL_thread.c	Thu Mar 07 15:37:08 2013 -0800
     8.2 +++ b/src/thread/SDL_thread.c	Thu Mar 07 20:12:40 2013 -0800
     8.3 @@ -85,7 +85,7 @@
     8.4              return;
     8.5          }
     8.6      }
     8.7 -    SDL_mutexP(thread_lock);
     8.8 +    SDL_LockMutex(thread_lock);
     8.9  
    8.10      /* Expand the list of threads, if necessary */
    8.11  #ifdef DEBUG_THREADS
    8.12 @@ -118,7 +118,7 @@
    8.13      if (!thread_lock) {
    8.14          return;
    8.15      }
    8.16 -    SDL_mutexP(thread_lock);
    8.17 +    SDL_LockMutex(thread_lock);
    8.18      for (i = 0; i < SDL_numthreads; ++i) {
    8.19          if (thread == SDL_Threads[i]) {
    8.20              break;
    8.21 @@ -164,7 +164,7 @@
    8.22          SDL_threadID this_thread;
    8.23  
    8.24          this_thread = SDL_ThreadID();
    8.25 -        SDL_mutexP(thread_lock);
    8.26 +        SDL_LockMutex(thread_lock);
    8.27          for (i = 0; i < SDL_numthreads; ++i) {
    8.28              if (this_thread == SDL_Threads[i]->threadid) {
    8.29                  errbuf = &SDL_Threads[i]->errbuf;
     9.1 --- a/src/thread/generic/SDL_sysmutex.c	Thu Mar 07 15:37:08 2013 -0800
     9.2 +++ b/src/thread/generic/SDL_sysmutex.c	Thu Mar 07 20:12:40 2013 -0800
     9.3 @@ -70,7 +70,7 @@
     9.4  
     9.5  /* Lock the mutex */
     9.6  int
     9.7 -SDL_mutexP(SDL_mutex * mutex)
     9.8 +SDL_LockMutex(SDL_mutex * mutex)
     9.9  {
    9.10  #if SDL_THREADS_DISABLED
    9.11      return 0;
    10.1 --- a/src/thread/generic/SDL_syssem.c	Thu Mar 07 15:37:08 2013 -0800
    10.2 +++ b/src/thread/generic/SDL_syssem.c	Thu Mar 07 20:12:40 2013 -0800
    10.3 @@ -123,8 +123,8 @@
    10.4          }
    10.5          SDL_DestroyCond(sem->count_nonzero);
    10.6          if (sem->count_lock) {
    10.7 -            SDL_mutexP(sem->count_lock);
    10.8 -            SDL_mutexV(sem->count_lock);
    10.9 +            SDL_LockMutex(sem->count_lock);
   10.10 +            SDL_UnlockMutex(sem->count_lock);
   10.11              SDL_DestroyMutex(sem->count_lock);
   10.12          }
   10.13          SDL_free(sem);
    11.1 --- a/src/thread/nds/SDL_sysmutex.c	Thu Mar 07 15:37:08 2013 -0800
    11.2 +++ b/src/thread/nds/SDL_sysmutex.c	Thu Mar 07 20:12:40 2013 -0800
    11.3 @@ -78,7 +78,7 @@
    11.4  
    11.5  /* Lock the mutex */
    11.6  int
    11.7 -SDL_mutexP(SDL_mutex * mutex)
    11.8 +SDL_LockMutex(SDL_mutex * mutex)
    11.9  {
   11.10  #ifdef DISABLE_THREADS
   11.11      return 0;
   11.12 @@ -143,7 +143,7 @@
   11.13  
   11.14  /* Unlock the mutex */
   11.15  int
   11.16 -SDL_mutexV(SDL_mutex * mutex)
   11.17 +SDL_UnlockMutex(SDL_mutex * mutex)
   11.18  {
   11.19  #ifdef DISABLE_THREADS
   11.20      return 0;
    12.1 --- a/src/thread/nds/SDL_syssem.c	Thu Mar 07 15:37:08 2013 -0800
    12.2 +++ b/src/thread/nds/SDL_syssem.c	Thu Mar 07 20:12:40 2013 -0800
    12.3 @@ -129,8 +129,8 @@
    12.4              SDL_Delay(10);
    12.5          }
    12.6          SDL_DestroyCond(sem->count_nonzero);
    12.7 -        SDL_mutexP(sem->count_lock);
    12.8 -        SDL_mutexV(sem->count_lock);
    12.9 +        SDL_LockMutex(sem->count_lock);
   12.10 +        SDL_UnlockMutex(sem->count_lock);
   12.11          SDL_DestroyMutex(sem->count_lock);
   12.12          free(sem);
   12.13      }
    13.1 --- a/src/thread/pthread/SDL_sysmutex.c	Thu Mar 07 15:37:08 2013 -0800
    13.2 +++ b/src/thread/pthread/SDL_sysmutex.c	Thu Mar 07 20:12:40 2013 -0800
    13.3 @@ -79,7 +79,7 @@
    13.4  
    13.5  /* Lock the mutex */
    13.6  int
    13.7 -SDL_mutexP(SDL_mutex * mutex)
    13.8 +SDL_LockMutex(SDL_mutex * mutex)
    13.9  {
   13.10      int retval;
   13.11  #if FAKE_RECURSIVE_MUTEX
   13.12 @@ -165,7 +165,7 @@
   13.13  }
   13.14  
   13.15  int
   13.16 -SDL_mutexV(SDL_mutex * mutex)
   13.17 +SDL_UnlockMutex(SDL_mutex * mutex)
   13.18  {
   13.19      int retval;
   13.20  
    14.1 --- a/src/thread/windows/SDL_sysmutex.c	Thu Mar 07 15:37:08 2013 -0800
    14.2 +++ b/src/thread/windows/SDL_sysmutex.c	Thu Mar 07 20:12:40 2013 -0800
    14.3 @@ -64,7 +64,7 @@
    14.4  
    14.5  /* Lock the mutex */
    14.6  int
    14.7 -SDL_mutexP(SDL_mutex * mutex)
    14.8 +SDL_LockMutex(SDL_mutex * mutex)
    14.9  {
   14.10      if (mutex == NULL) {
   14.11          SDL_SetError("Passed a NULL mutex");
   14.12 @@ -93,7 +93,7 @@
   14.13  
   14.14  /* Unlock the mutex */
   14.15  int
   14.16 -SDL_mutexV(SDL_mutex * mutex)
   14.17 +SDL_UnlockMutex(SDL_mutex * mutex)
   14.18  {
   14.19      if (mutex == NULL) {
   14.20          SDL_SetError("Passed a NULL mutex");
    15.1 --- a/src/timer/SDL_timer.c	Thu Mar 07 15:37:08 2013 -0800
    15.2 +++ b/src/timer/SDL_timer.c	Thu Mar 07 20:12:40 2013 -0800
    15.3 @@ -334,10 +334,10 @@
    15.4      entry->timer = timer;
    15.5      entry->timerID = timer->timerID;
    15.6  
    15.7 -    SDL_mutexP(data->timermap_lock);
    15.8 +    SDL_LockMutex(data->timermap_lock);
    15.9      entry->next = data->timermap;
   15.10      data->timermap = entry;
   15.11 -    SDL_mutexV(data->timermap_lock);
   15.12 +    SDL_UnlockMutex(data->timermap_lock);
   15.13  
   15.14      /* Add the timer to the pending list for the timer thread */
   15.15      SDL_AtomicLock(&data->lock);
   15.16 @@ -359,7 +359,7 @@
   15.17      SDL_bool canceled = SDL_FALSE;
   15.18  
   15.19      /* Find the timer */
   15.20 -    SDL_mutexP(data->timermap_lock);
   15.21 +    SDL_LockMutex(data->timermap_lock);
   15.22      prev = NULL;
   15.23      for (entry = data->timermap; entry; prev = entry, entry = entry->next) {
   15.24          if (entry->timerID == id) {
   15.25 @@ -371,7 +371,7 @@
   15.26              break;
   15.27          }
   15.28      }
   15.29 -    SDL_mutexV(data->timermap_lock);
   15.30 +    SDL_UnlockMutex(data->timermap_lock);
   15.31  
   15.32      if (entry) {
   15.33          if (!entry->timer->canceled) {
    16.1 --- a/test/testatomic.c	Thu Mar 07 15:37:08 2013 -0800
    16.2 +++ b/test/testatomic.c	Thu Mar 07 20:12:40 2013 -0800
    16.3 @@ -412,7 +412,7 @@
    16.4      int delta;
    16.5      SDL_bool status = SDL_FALSE;
    16.6  
    16.7 -    SDL_mutexP(queue->mutex);
    16.8 +    SDL_LockMutex(queue->mutex);
    16.9  
   16.10      queue_pos = (unsigned)queue->enqueue_pos.value;
   16.11      entry = &queue->entries[queue_pos & WRAP_MASK];
   16.12 @@ -432,7 +432,7 @@
   16.13          printf("ERROR: mutex failed!\n");
   16.14      }
   16.15  
   16.16 -    SDL_mutexV(queue->mutex);
   16.17 +    SDL_UnlockMutex(queue->mutex);
   16.18  
   16.19      return status;
   16.20  }
   16.21 @@ -445,7 +445,7 @@
   16.22      int delta;
   16.23      SDL_bool status = SDL_FALSE;
   16.24  
   16.25 -    SDL_mutexP(queue->mutex);
   16.26 +    SDL_LockMutex(queue->mutex);
   16.27  
   16.28      queue_pos = (unsigned)queue->dequeue_pos.value;
   16.29      entry = &queue->entries[queue_pos & WRAP_MASK];
   16.30 @@ -465,7 +465,7 @@
   16.31          printf("ERROR: mutex failed!\n");
   16.32      }
   16.33  
   16.34 -    SDL_mutexV(queue->mutex);
   16.35 +    SDL_UnlockMutex(queue->mutex);
   16.36  
   16.37      return status;
   16.38  }
    17.1 --- a/test/testlock.c	Thu Mar 07 15:37:08 2013 -0800
    17.2 +++ b/test/testlock.c	Thu Mar 07 20:12:40 2013 -0800
    17.3 @@ -69,14 +69,14 @@
    17.4          signal(SIGTERM, closemutex);
    17.5      while (!doterminate) {
    17.6          printf("Process %lu ready to work\n", SDL_ThreadID());
    17.7 -        if (SDL_mutexP(mutex) < 0) {
    17.8 +        if (SDL_LockMutex(mutex) < 0) {
    17.9              fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
   17.10              exit(1);
   17.11          }
   17.12          printf("Process %lu, working!\n", SDL_ThreadID());
   17.13          SDL_Delay(1 * 1000);
   17.14          printf("Process %lu, done!\n", SDL_ThreadID());
   17.15 -        if (SDL_mutexV(mutex) < 0) {
   17.16 +        if (SDL_UnlockMutex(mutex) < 0) {
   17.17              fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
   17.18              exit(1);
   17.19          }