Merge pull request #3548 from frangarcj/master

(VITA) Use pthreads
This commit is contained in:
Twinaphex 2016-09-09 17:56:34 +02:00 committed by GitHub
commit 1bf6887c59
5 changed files with 41 additions and 36 deletions

View File

@ -378,6 +378,9 @@ CFLAGS += -DHAVE_THREADS
ifeq ($(platform), psp1)
LIBS += -lpthread-psp
endif
ifeq ($(platform), vita)
LIBS += -lpthread
endif
endif
ifeq ($(HAVE_RSOUND), 1)

View File

@ -45,8 +45,8 @@ typedef struct psp_audio
volatile bool running;
volatile uint16_t read_pos;
volatile uint16_t write_pos;
#ifdef VITA
#ifdef VITA
char lock[32] __attribute__ ((aligned (8)));
char cond_lock[32] __attribute__ ((aligned (8)));
char cond[32] __attribute__ ((aligned (8)));
@ -101,8 +101,8 @@ static int audioMainLoop(SceSize args, void* argp)
#ifdef VITA
sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1);
sceKernelSignalLwCond(&psp->cond);
sceKernelSignalLwCond((struct SceKernelLwCondWork*)&psp->cond);
sceAudioOutOutput(port,
cond ? (psp->zeroBuffer)
: (psp->buffer + read_pos_2));
@ -145,7 +145,7 @@ static void *psp_audio_init(const char *device,
sceKernelCreateLwMutex((struct SceKernelLwMutexWork*)&psp->lock, "audio_get_lock", 0, 0, 0);
sceKernelCreateLwMutex((struct SceKernelLwMutexWork*)&psp->cond_lock, "audio_get_cond_lock", 0, 0, 0);
sceKernelCreateLwCond(&psp->cond, "audio_get_cond", 0, &psp->cond_lock, 0);
sceKernelCreateLwCond((struct SceKernelLwCondWork*)&psp->cond, "audio_get_cond", 0, (struct SceKernelLwMutexWork*)&psp->cond_lock, 0);
psp->thread = sceKernelCreateThread
("audioMainLoop", audioMainLoop, 0x10000100, 0x10000, 0, 0, NULL);
#else
@ -172,7 +172,7 @@ static void psp_audio_free(void *data)
sceKernelWaitThreadEnd(psp->thread, NULL, &timeout);
sceKernelDeleteLwMutex((struct SceKernelLwMutexWork*)&psp->lock);
sceKernelDeleteLwMutex((struct SceKernelLwMutexWork*)&psp->cond_lock);
sceKernelDeleteLwCond(&psp->cond);
sceKernelDeleteLwCond((struct SceKernelLwCondWork*)&psp->cond);
#else
sceKernelWaitThreadEnd(psp->thread, &timeout);
#endif
@ -187,7 +187,7 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
psp_audio_t* psp = (psp_audio_t*)data;
uint16_t write_pos = psp->write_pos;
uint16_t sampleCount = size / sizeof(uint32_t);
#ifdef VITA
if (psp->nonblocking)
{
@ -198,7 +198,7 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
while (AUDIO_BUFFER_SIZE - ((uint16_t)
(psp->write_pos - psp->read_pos) & AUDIO_BUFFER_SIZE_MASK) < size){
sceKernelWaitLwCond(&psp->cond, 0);
sceKernelWaitLwCond((struct SceKernelLwCondWork*)&psp->cond, 0);
}
sceKernelLockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1, 0);
@ -218,11 +218,11 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
write_pos &= AUDIO_BUFFER_SIZE_MASK;
psp->write_pos = write_pos;
sceKernelUnlockLwMutex((struct SceKernelLwMutexWork*)&psp->lock, 1);
return size;
#else
#if 0
if (psp->nonblocking)

View File

@ -23,6 +23,7 @@
#include <psp2/power.h>
#include <psp2/sysmodule.h>
#include <psp2/appmgr.h>
#include <pthread.h>
#else
#include <pspkernel.h>
#include <pspdebug.h>
@ -298,6 +299,7 @@ static void frontend_psp_init(void *data)
#ifdef VITA
scePowerSetArmClockFrequency(444);
sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
pthread_init();
#else
(void)data;
/* initialize debug screen */

View File

@ -73,7 +73,7 @@ static int psp_thread_wrap(SceSize args, void *argp)
static INLINE int pthread_create(pthread_t *thread,
const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
{
sprintf(name_buffer, "0x%08X", (uint32_t) thread);
sprintf(name_buffer, "0x%08X", (unsigned int) thread);
#ifdef VITA
*thread = sceKernelCreateThread(name_buffer, psp_thread_wrap,
@ -93,7 +93,7 @@ static INLINE int pthread_create(pthread_t *thread,
static INLINE int pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *attr)
{
sprintf(name_buffer, "0x%08X", (uint32_t) mutex);
sprintf(name_buffer, "0x%08X", (unsigned int) mutex);
#ifdef VITA
*mutex = sceKernelCreateMutex(name_buffer, 0, 0, 0);
@ -224,7 +224,7 @@ static INLINE int pthread_cond_init(pthread_cond_t *cond,
if(cond->mutex<0){
return cond->mutex;
}
sprintf(name_buffer, "0x%08X", (uint32_t) cond);
sprintf(name_buffer, "0x%08X", (unsigned int) cond);
//cond->sema = sceKernelCreateCond(name_buffer, 0, cond->mutex, 0);
cond->sema = sceKernelCreateSema(name_buffer, 0, 0, 1, 0);
if(cond->sema<0){
@ -251,7 +251,7 @@ static INLINE int pthread_cond_signal(pthread_cond_t *cond)
if (cond->waiting)
{
--cond->waiting;
int ret = sceKernelSignalSema(cond->sema, 1);
sceKernelSignalSema(cond->sema, 1);
}
pthread_mutex_unlock(&cond->mutex);
return 0;

View File

@ -41,7 +41,7 @@
#endif
#elif defined(GEKKO)
#include "gx_pthread.h"
#elif defined(PSP) || defined(VITA)
#elif defined(PSP)
#include "psp_pthread.h"
#elif defined(__CELLOS_LV2__)
#include <pthread.h>
@ -154,11 +154,11 @@ error:
/**
* sthread_detach:
* @thread : pointer to thread object
* @thread : pointer to thread object
*
* Detach a thread. When a detached thread terminates, its
* resource sare automatically released back to the system
* without the need for another thread to join with the
* without the need for another thread to join with the
* terminated thread.
*
* Returns: 0 on success, otherwise it returns a non-zero error number.
@ -176,13 +176,13 @@ int sthread_detach(sthread_t *thread)
/**
* sthread_join:
* @thread : pointer to thread object
* @thread : pointer to thread object
*
* Join with a terminated thread. Waits for the thread specified by
* @thread to terminate. If that thread has already terminated, then
* it will return immediately. The thread specified by @thread must
* be joinable.
*
*
* Returns: 0 on success, otherwise it returns a non-zero error number.
*/
void sthread_join(sthread_t *thread)
@ -198,13 +198,13 @@ void sthread_join(sthread_t *thread)
/**
* sthread_isself:
* @thread : pointer to thread object
* @thread : pointer to thread object
*
* Join with a terminated thread. Waits for the thread specified by
* @thread to terminate. If that thread has already terminated, then
* it will return immediately. The thread specified by @thread must
* be joinable.
*
*
* Returns: true (1) if calling thread is the specified thread
*/
bool sthread_isself(sthread_t *thread)
@ -248,7 +248,7 @@ error:
/**
* slock_free:
* @lock : pointer to mutex object
* @lock : pointer to mutex object
*
* Frees a mutex.
**/
@ -267,7 +267,7 @@ void slock_free(slock_t *lock)
/**
* slock_lock:
* @lock : pointer to mutex object
* @lock : pointer to mutex object
*
* Locks a mutex. If a mutex is already locked by
* another thread, the calling thread shall block until
@ -284,7 +284,7 @@ void slock_lock(slock_t *lock)
/**
* slock_unlock:
* @lock : pointer to mutex object
* @lock : pointer to mutex object
*
* Unlocks a mutex.
**/
@ -333,7 +333,7 @@ error:
/**
* scond_free:
* @cond : pointer to condition variable object
* @cond : pointer to condition variable object
*
* Frees a condition variable.
**/
@ -352,16 +352,16 @@ void scond_free(scond_t *cond)
/**
* scond_wait:
* @cond : pointer to condition variable object
* @lock : pointer to mutex object
* @cond : pointer to condition variable object
* @lock : pointer to mutex object
*
* Block on a condition variable (i.e. wait on a condition).
* Block on a condition variable (i.e. wait on a condition).
**/
void scond_wait(scond_t *cond, slock_t *lock)
{
#ifdef USE_WIN32_THREADS
WaitForSingleObject(cond->event, 0);
SignalObjectAndWait(lock->lock, cond->event, INFINITE, FALSE);
slock_lock(lock);
#else
@ -371,15 +371,15 @@ void scond_wait(scond_t *cond, slock_t *lock)
/**
* scond_broadcast:
* @cond : pointer to condition variable object
* @cond : pointer to condition variable object
*
* Broadcast a condition. Unblocks all threads currently blocked
* on the specified condition variable @cond.
* on the specified condition variable @cond.
**/
int scond_broadcast(scond_t *cond)
{
#ifdef USE_WIN32_THREADS
/* FIXME _- check how this function should differ
/* FIXME _- check how this function should differ
* from scond_signal implementation. */
SetEvent(cond->event);
return 0;
@ -390,10 +390,10 @@ int scond_broadcast(scond_t *cond)
/**
* scond_signal:
* @cond : pointer to condition variable object
* @cond : pointer to condition variable object
*
* Signal a condition. Unblocks at least one of the threads currently blocked
* on the specified condition variable @cond.
* on the specified condition variable @cond.
**/
void scond_signal(scond_t *cond)
{
@ -406,8 +406,8 @@ void scond_signal(scond_t *cond)
/**
* scond_wait_timeout:
* @cond : pointer to condition variable object
* @lock : pointer to mutex object
* @cond : pointer to condition variable object
* @lock : pointer to mutex object
* @timeout_us : timeout (in microseconds)
*
* Try to block on a condition variable (i.e. wait on a condition) until