mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 07:13:35 +00:00
remove rsemaphore (#8645)
This commit is contained in:
parent
3b1ec7d30e
commit
8ee1e7b39f
@ -868,7 +868,6 @@ endif
|
|||||||
|
|
||||||
ifeq ($(HAVE_THREADS), 1)
|
ifeq ($(HAVE_THREADS), 1)
|
||||||
OBJ += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.o \
|
OBJ += $(LIBRETRO_COMM_DIR)/rthreads/rthreads.o \
|
||||||
$(LIBRETRO_COMM_DIR)/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
|
||||||
|
@ -1159,7 +1159,6 @@ THREAD
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#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"
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2005 Allen B. Downey
|
|
||||||
|
|
||||||
This file contains an example program from The Little Book of
|
|
||||||
Semaphores, available from Green Tea Press, greenteapress.com
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, see http://www.gnu.org/licenses/gpl.html
|
|
||||||
or write to the Free Software Foundation, Inc., 51 Franklin St,
|
|
||||||
Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Code taken from http://greenteapress.com/semaphores/semaphore.c
|
|
||||||
* and changed to use libretro-common's mutexes and conditions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <rthreads/rthreads.h>
|
|
||||||
#include <rthreads/rsemaphore.h>
|
|
||||||
|
|
||||||
struct ssem
|
|
||||||
{
|
|
||||||
int value;
|
|
||||||
int wakeups;
|
|
||||||
slock_t *mutex;
|
|
||||||
scond_t *cond;
|
|
||||||
};
|
|
||||||
|
|
||||||
ssem_t *ssem_new(int value)
|
|
||||||
{
|
|
||||||
ssem_t *semaphore = (ssem_t*)calloc(1, sizeof(*semaphore));
|
|
||||||
|
|
||||||
if (!semaphore)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
semaphore->value = value;
|
|
||||||
semaphore->wakeups = 0;
|
|
||||||
semaphore->mutex = slock_new();
|
|
||||||
|
|
||||||
if (!semaphore->mutex)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
semaphore->cond = scond_new();
|
|
||||||
|
|
||||||
if (!semaphore->cond)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return semaphore;
|
|
||||||
|
|
||||||
error:
|
|
||||||
if (semaphore->mutex)
|
|
||||||
slock_free(semaphore->mutex);
|
|
||||||
semaphore->mutex = NULL;
|
|
||||||
if (semaphore)
|
|
||||||
free((void*)semaphore);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ssem_free(ssem_t *semaphore)
|
|
||||||
{
|
|
||||||
if (!semaphore)
|
|
||||||
return;
|
|
||||||
|
|
||||||
scond_free(semaphore->cond);
|
|
||||||
slock_free(semaphore->mutex);
|
|
||||||
free((void*)semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ssem_wait(ssem_t *semaphore)
|
|
||||||
{
|
|
||||||
if (!semaphore)
|
|
||||||
return;
|
|
||||||
|
|
||||||
slock_lock(semaphore->mutex);
|
|
||||||
semaphore->value--;
|
|
||||||
|
|
||||||
if (semaphore->value < 0)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
scond_wait(semaphore->cond, semaphore->mutex);
|
|
||||||
}while (semaphore->wakeups < 1);
|
|
||||||
|
|
||||||
semaphore->wakeups--;
|
|
||||||
}
|
|
||||||
|
|
||||||
slock_unlock(semaphore->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ssem_signal(ssem_t *semaphore)
|
|
||||||
{
|
|
||||||
if (!semaphore)
|
|
||||||
return;
|
|
||||||
|
|
||||||
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