Move ra_semaphore to libretro-common - rename rsemaphore

This commit is contained in:
twinaphex 2015-10-28 07:08:27 +01:00
parent 2fdba18992
commit 4d8ead2fb7
5 changed files with 27 additions and 23 deletions

View File

@ -471,6 +471,7 @@ endif
ifeq ($(HAVE_THREADS), 1) ifeq ($(HAVE_THREADS), 1)
OBJ += autosave.o \ OBJ += autosave.o \
libretro-common/rthreads/rthreads.o \ libretro-common/rthreads/rthreads.o \
libretro-common/rthreads/rsemaphore.o \
gfx/video_thread_wrapper.o \ gfx/video_thread_wrapper.o \
audio/audio_thread_wrapper.o audio/audio_thread_wrapper.o
DEFINES += -DHAVE_THREADS DEFINES += -DHAVE_THREADS
@ -868,7 +869,7 @@ ifeq ($(HAVE_NETWORKING), 1)
ifeq ($(HAVE_CHEEVOS), 1) ifeq ($(HAVE_CHEEVOS), 1)
ifeq ($(HAVE_THREADS), 1) ifeq ($(HAVE_THREADS), 1)
DEFINES += -DHAVE_CHEEVOS DEFINES += -DHAVE_CHEEVOS
OBJ += cheevos.o ra_semaphore.o async_job.o libretro-common/utils/md5.o OBJ += cheevos.o async_job.o libretro-common/utils/md5.o
endif endif
endif endif
endif endif

View File

@ -16,7 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <rthreads/rthreads.h> #include <rthreads/rthreads.h>
#include <ra_semaphore.h> #include <rthreads/rsemaphore.h>
#include <async_job.h> #include <async_job.h>
typedef struct async_job_node async_job_node_t; typedef struct async_job_node async_job_node_t;

View File

@ -90,7 +90,6 @@ ACHIEVEMENTS
#include "../libretro-common/formats/json/jsonsax.c" #include "../libretro-common/formats/json/jsonsax.c"
#include "../libretro-common/utils/md5.c" #include "../libretro-common/utils/md5.c"
#include "../net_http_special.c" #include "../net_http_special.c"
#include "../ra_semaphore.c"
#include "../async_job.c" #include "../async_job.c"
#include "../cheevos.c" #include "../cheevos.c"
#endif #endif
@ -733,6 +732,7 @@ THREAD
#include "../thread/xenon_sdl_threads.c" #include "../thread/xenon_sdl_threads.c"
#elif defined(HAVE_THREADS) #elif defined(HAVE_THREADS)
#include "../libretro-common/rthreads/rthreads.c" #include "../libretro-common/rthreads/rthreads.c"
#include "../libretro-common/rthreads/rsemaphore.c"
#include "../gfx/video_thread_wrapper.c" #include "../gfx/video_thread_wrapper.c"
#include "../audio/audio_thread_wrapper.c" #include "../audio/audio_thread_wrapper.c"
#include "../autosave.c" #include "../autosave.c"

View File

@ -13,8 +13,8 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __RARCH_SEMAPHORE_H #ifndef __LIBRETRO_SDK_SEMAPHORE_H
#define __RARCH_SEMAPHORE_H #define __LIBRETRO_SDK_SEMAPHORE_H
typedef struct ssem ssem_t; typedef struct ssem ssem_t;

View File

@ -27,11 +27,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <rthreads/rthreads.h> #include <rthreads/rthreads.h>
#include <ra_semaphore.h> #include <rthreads/rsemaphore.h>
struct ssem struct ssem
{ {
int value, wakeups; int value;
int wakeups;
slock_t *mutex; slock_t *mutex;
scond_t *cond; scond_t *cond;
}; };
@ -39,52 +40,54 @@ struct ssem
ssem_t *ssem_new(int value) ssem_t *ssem_new(int value)
{ {
ssem_t *semaphore = (ssem_t*)malloc(sizeof(*semaphore)); ssem_t *semaphore = (ssem_t*)malloc(sizeof(*semaphore));
if (semaphore) if (semaphore)
{ {
semaphore->value = value; semaphore->value = value;
semaphore->wakeups = 0; semaphore->wakeups = 0;
semaphore->mutex = slock_new(); semaphore->mutex = slock_new();
if (semaphore->mutex) if (semaphore->mutex)
{ {
semaphore->cond = scond_new(); semaphore->cond = scond_new();
if (semaphore->cond) if (semaphore->cond)
return semaphore; return semaphore;
slock_free(semaphore->mutex); slock_free(semaphore->mutex);
} }
free((void*)semaphore); free((void*)semaphore);
} }
return NULL; return NULL;
} }
void ssem_free(ssem_t *semaphore) void ssem_free(ssem_t *semaphore)
{ {
scond_free(semaphore->cond); if (!semaphore)
slock_free(semaphore->mutex); return;
free((void*)semaphore);
scond_free(semaphore->cond);
slock_free(semaphore->mutex);
free((void*)semaphore);
} }
void ssem_wait(ssem_t *semaphore) void ssem_wait(ssem_t *semaphore)
{ {
slock_lock(semaphore->mutex); slock_lock(semaphore->mutex);
semaphore->value--; semaphore->value--;
if (semaphore->value < 0) if (semaphore->value < 0)
{ {
do do
{ {
scond_wait(semaphore->cond, semaphore->mutex); scond_wait(semaphore->cond, semaphore->mutex);
} }while (semaphore->wakeups < 1);
while (semaphore->wakeups < 1);
semaphore->wakeups--; semaphore->wakeups--;
} }
slock_unlock(semaphore->mutex); slock_unlock(semaphore->mutex);
} }
@ -92,12 +95,12 @@ void ssem_signal(ssem_t *semaphore)
{ {
slock_lock(semaphore->mutex); slock_lock(semaphore->mutex);
semaphore->value++; semaphore->value++;
if (semaphore->value <= 0) if (semaphore->value <= 0)
{ {
semaphore->wakeups++; semaphore->wakeups++;
scond_signal(semaphore->cond); scond_signal(semaphore->cond);
} }
slock_unlock(semaphore->mutex); slock_unlock(semaphore->mutex);
} }