mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-18 08:52:41 +00:00
Move ra_semaphore to libretro-common - rename rsemaphore
This commit is contained in:
parent
2fdba18992
commit
4d8ead2fb7
@ -471,6 +471,7 @@ endif
|
||||
ifeq ($(HAVE_THREADS), 1)
|
||||
OBJ += autosave.o \
|
||||
libretro-common/rthreads/rthreads.o \
|
||||
libretro-common/rthreads/rsemaphore.o \
|
||||
gfx/video_thread_wrapper.o \
|
||||
audio/audio_thread_wrapper.o
|
||||
DEFINES += -DHAVE_THREADS
|
||||
@ -868,7 +869,7 @@ ifeq ($(HAVE_NETWORKING), 1)
|
||||
ifeq ($(HAVE_CHEEVOS), 1)
|
||||
ifeq ($(HAVE_THREADS), 1)
|
||||
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
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <ra_semaphore.h>
|
||||
#include <rthreads/rsemaphore.h>
|
||||
#include <async_job.h>
|
||||
|
||||
typedef struct async_job_node async_job_node_t;
|
||||
|
@ -90,7 +90,6 @@ ACHIEVEMENTS
|
||||
#include "../libretro-common/formats/json/jsonsax.c"
|
||||
#include "../libretro-common/utils/md5.c"
|
||||
#include "../net_http_special.c"
|
||||
#include "../ra_semaphore.c"
|
||||
#include "../async_job.c"
|
||||
#include "../cheevos.c"
|
||||
#endif
|
||||
@ -733,6 +732,7 @@ THREAD
|
||||
#include "../thread/xenon_sdl_threads.c"
|
||||
#elif defined(HAVE_THREADS)
|
||||
#include "../libretro-common/rthreads/rthreads.c"
|
||||
#include "../libretro-common/rthreads/rsemaphore.c"
|
||||
#include "../gfx/video_thread_wrapper.c"
|
||||
#include "../audio/audio_thread_wrapper.c"
|
||||
#include "../autosave.c"
|
||||
|
@ -13,8 +13,8 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __RARCH_SEMAPHORE_H
|
||||
#define __RARCH_SEMAPHORE_H
|
||||
#ifndef __LIBRETRO_SDK_SEMAPHORE_H
|
||||
#define __LIBRETRO_SDK_SEMAPHORE_H
|
||||
|
||||
typedef struct ssem ssem_t;
|
||||
|
@ -27,11 +27,12 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <ra_semaphore.h>
|
||||
#include <rthreads/rsemaphore.h>
|
||||
|
||||
struct ssem
|
||||
{
|
||||
int value, wakeups;
|
||||
int value;
|
||||
int wakeups;
|
||||
slock_t *mutex;
|
||||
scond_t *cond;
|
||||
};
|
||||
@ -39,52 +40,54 @@ struct ssem
|
||||
ssem_t *ssem_new(int value)
|
||||
{
|
||||
ssem_t *semaphore = (ssem_t*)malloc(sizeof(*semaphore));
|
||||
|
||||
|
||||
if (semaphore)
|
||||
{
|
||||
semaphore->value = value;
|
||||
semaphore->wakeups = 0;
|
||||
semaphore->mutex = slock_new();
|
||||
|
||||
|
||||
if (semaphore->mutex)
|
||||
{
|
||||
semaphore->cond = scond_new();
|
||||
|
||||
|
||||
if (semaphore->cond)
|
||||
return semaphore;
|
||||
|
||||
|
||||
slock_free(semaphore->mutex);
|
||||
}
|
||||
|
||||
|
||||
free((void*)semaphore);
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ssem_free(ssem_t *semaphore)
|
||||
{
|
||||
scond_free(semaphore->cond);
|
||||
slock_free(semaphore->mutex);
|
||||
free((void*)semaphore);
|
||||
if (!semaphore)
|
||||
return;
|
||||
|
||||
scond_free(semaphore->cond);
|
||||
slock_free(semaphore->mutex);
|
||||
free((void*)semaphore);
|
||||
}
|
||||
|
||||
void ssem_wait(ssem_t *semaphore)
|
||||
{
|
||||
slock_lock(semaphore->mutex);
|
||||
semaphore->value--;
|
||||
|
||||
|
||||
if (semaphore->value < 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
scond_wait(semaphore->cond, semaphore->mutex);
|
||||
}
|
||||
while (semaphore->wakeups < 1);
|
||||
|
||||
}while (semaphore->wakeups < 1);
|
||||
|
||||
semaphore->wakeups--;
|
||||
}
|
||||
|
||||
|
||||
slock_unlock(semaphore->mutex);
|
||||
}
|
||||
|
||||
@ -92,12 +95,12 @@ void ssem_signal(ssem_t *semaphore)
|
||||
{
|
||||
slock_lock(semaphore->mutex);
|
||||
semaphore->value++;
|
||||
|
||||
|
||||
if (semaphore->value <= 0)
|
||||
{
|
||||
semaphore->wakeups++;
|
||||
scond_signal(semaphore->cond);
|
||||
}
|
||||
|
||||
|
||||
slock_unlock(semaphore->mutex);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user