(psp pthreads) Buildfixes
This commit is contained in:
parent
a57df7d43f
commit
c4f06f2ef2
|
@ -29,9 +29,9 @@
|
|||
#ifndef _TLS_HELPER_H_
|
||||
#define _TLS_HELPER_H_
|
||||
|
||||
#include "pte_osal.h"
|
||||
#include "../../pte_osal.h"
|
||||
|
||||
/// @todo document..
|
||||
/* @todo document.. */
|
||||
|
||||
pte_osResult pteTlsGlobalInit(int maxEntries);
|
||||
void * pteTlsThreadInit(void);
|
||||
|
|
|
@ -30,17 +30,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pspkerror.h>
|
||||
#include "pte_osal.h"
|
||||
#include "pthread.h"
|
||||
#include "../helper/tls-helper.h"
|
||||
|
||||
/* For ftime */
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
#define MAX_PSP_UID 2048 // SWAG
|
||||
#include <pspkerror.h>
|
||||
|
||||
#include "../../pte_osal.h"
|
||||
#include "../../pthread.h"
|
||||
#include "../helper/tls-helper.h"
|
||||
|
||||
#define MAX_PSP_UID 2048 /* SWAG */
|
||||
|
||||
#define DEFAULT_STACK_SIZE_BYTES 4096
|
||||
|
||||
|
@ -181,15 +183,11 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
|
|||
pspThreadData *pThreadData;
|
||||
|
||||
if (threadNum++ > MAX_PSP_UID)
|
||||
{
|
||||
threadNum = 0;
|
||||
}
|
||||
|
||||
/* Make sure that the stack we're going to allocate is big enough */
|
||||
if (stackSize < DEFAULT_STACK_SIZE_BYTES)
|
||||
{
|
||||
stackSize = DEFAULT_STACK_SIZE_BYTES;
|
||||
}
|
||||
|
||||
/* Allocate TLS structure for this thread. */
|
||||
pTls = pteTlsThreadInit();
|
||||
|
@ -240,7 +238,9 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
|
|||
|
||||
pspAttr = 0;
|
||||
|
||||
// printf("%s %p %d %d %d\n",threadName, pspStubThreadEntry, initialPriority, stackSize, pspAttr);
|
||||
#if 0
|
||||
printf("%s %p %d %d %d\n",threadName, pspStubThreadEntry, initialPriority, stackSize, pspAttr);
|
||||
#endif
|
||||
threadId = sceKernelCreateThread(threadName,
|
||||
pspStubThreadEntry,
|
||||
initialPriority,
|
||||
|
@ -274,7 +274,6 @@ FAIL0:
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
pte_osResult pte_osThreadStart(pte_osThreadHandle osThreadHandle)
|
||||
{
|
||||
sceKernelStartThread(osThreadHandle, 0, NULL);
|
||||
|
@ -285,12 +284,8 @@ pte_osResult pte_osThreadStart(pte_osThreadHandle osThreadHandle)
|
|||
|
||||
pte_osResult pte_osThreadDelete(pte_osThreadHandle handle)
|
||||
{
|
||||
pspThreadData *pThreadData;
|
||||
void *pTls;
|
||||
|
||||
pTls = getTlsStructFromThread(handle);
|
||||
|
||||
pThreadData = getThreadData(handle);
|
||||
void *pTls = getTlsStructFromThread(handle);
|
||||
pspThreadData *pThreadData = getThreadData(handle);
|
||||
|
||||
sceKernelDeleteSema(pThreadData->cancelSem);
|
||||
|
||||
|
@ -312,7 +307,7 @@ pte_osResult pte_osThreadExitAndDelete(pte_osThreadHandle handle)
|
|||
return PTE_OS_OK;
|
||||
}
|
||||
|
||||
void pte_osThreadExit()
|
||||
void pte_osThreadExit(void)
|
||||
{
|
||||
sceKernelExitThread(0);
|
||||
}
|
||||
|
@ -324,9 +319,7 @@ void pte_osThreadExit()
|
|||
pte_osResult pte_osThreadWaitForEnd(pte_osThreadHandle threadHandle)
|
||||
{
|
||||
pte_osResult result;
|
||||
pspThreadData *pThreadData;
|
||||
|
||||
pThreadData = getThreadData(sceKernelGetThreadId());
|
||||
pspThreadData *pThreadData = getThreadData(sceKernelGetThreadId());
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -360,14 +353,12 @@ pte_osResult pte_osThreadWaitForEnd(pte_osThreadHandle threadHandle)
|
|||
result = PTE_OS_INTERRUPTED;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing found and not timed out yet; let's yield so we're not
|
||||
* in busy loop.
|
||||
*/
|
||||
else
|
||||
sceKernelDelayThread(POLLING_DELAY_IN_us);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PTE_OS_GENERAL_FAILURE;
|
||||
|
@ -405,35 +396,22 @@ pte_osResult pte_osThreadSetPriority(pte_osThreadHandle threadHandle, int newPri
|
|||
|
||||
pte_osResult pte_osThreadCancel(pte_osThreadHandle threadHandle)
|
||||
{
|
||||
SceUID osResult;
|
||||
pte_osResult result;
|
||||
pspThreadData *pThreadData;
|
||||
|
||||
pThreadData = getThreadData(threadHandle);
|
||||
|
||||
osResult = sceKernelSignalSema(pThreadData->cancelSem, 1);
|
||||
pspThreadData *pThreadData = getThreadData(threadHandle);
|
||||
SceUID osResult = sceKernelSignalSema(pThreadData->cancelSem, 1);
|
||||
|
||||
if (osResult == SCE_KERNEL_ERROR_OK)
|
||||
{
|
||||
result = PTE_OS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
return PTE_OS_OK;
|
||||
|
||||
return result;
|
||||
return PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
pte_osResult pte_osThreadCheckCancel(pte_osThreadHandle threadHandle)
|
||||
{
|
||||
pspThreadData *pThreadData;
|
||||
SceKernelSemaInfo semInfo;
|
||||
SceUID osResult;
|
||||
pte_osResult result;
|
||||
|
||||
pThreadData = getThreadData(threadHandle);
|
||||
pspThreadData *pThreadData = getThreadData(threadHandle);
|
||||
|
||||
if (pThreadData != NULL)
|
||||
{
|
||||
|
@ -442,25 +420,17 @@ pte_osResult pte_osThreadCheckCancel(pte_osThreadHandle threadHandle)
|
|||
if (osResult == SCE_KERNEL_ERROR_OK)
|
||||
{
|
||||
if (semInfo.currentCount > 0)
|
||||
{
|
||||
result = PTE_OS_INTERRUPTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PTE_OS_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* sceKernelReferSemaStatus returned an error */
|
||||
result = PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* For some reason, we couldn't get thread data */
|
||||
result = PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
/* For some reason, we couldn't get thread data */
|
||||
else
|
||||
result = PTE_OS_GENERAL_FAILURE;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -470,17 +440,17 @@ void pte_osThreadSleep(unsigned int msecs)
|
|||
sceKernelDelayThread(msecs*1000);
|
||||
}
|
||||
|
||||
int pte_osThreadGetMinPriority()
|
||||
int pte_osThreadGetMinPriority(void)
|
||||
{
|
||||
return 17;
|
||||
}
|
||||
|
||||
int pte_osThreadGetMaxPriority()
|
||||
int pte_osThreadGetMaxPriority(void)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
int pte_osThreadGetDefaultPriority()
|
||||
int pte_osThreadGetDefaultPriority(void)
|
||||
{
|
||||
return 18;
|
||||
}
|
||||
|
@ -498,9 +468,7 @@ pte_osResult pte_osMutexCreate(pte_osMutexHandle *pHandle)
|
|||
pte_osMutexHandle handle;
|
||||
|
||||
if (mutexCtr++ > MAX_PSP_UID)
|
||||
{
|
||||
mutexCtr = 0;
|
||||
}
|
||||
|
||||
snprintf(mutexName,sizeof(mutexName),"mutex%d",mutexCtr);
|
||||
|
||||
|
@ -522,8 +490,6 @@ pte_osResult pte_osMutexDelete(pte_osMutexHandle handle)
|
|||
return PTE_OS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pte_osResult pte_osMutexLock(pte_osMutexHandle handle)
|
||||
{
|
||||
sceKernelWaitSema(handle, 1, NULL);
|
||||
|
@ -533,22 +499,14 @@ pte_osResult pte_osMutexLock(pte_osMutexHandle handle)
|
|||
|
||||
pte_osResult pte_osMutexTimedLock(pte_osMutexHandle handle, unsigned int timeoutMsecs)
|
||||
{
|
||||
pte_osResult result;
|
||||
SceUInt timeoutUsecs = timeoutMsecs*1000;
|
||||
|
||||
int status = sceKernelWaitSema(handle, 1, &timeoutUsecs);
|
||||
|
||||
/* Assume that any error from sceKernelWaitSema was due to a timeout */
|
||||
if (status < 0)
|
||||
{
|
||||
// Assume that any error from sceKernelWaitSema was due to a timeout
|
||||
result = PTE_OS_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PTE_OS_OK;
|
||||
}
|
||||
return PTE_OS_TIMEOUT;
|
||||
|
||||
return result;
|
||||
return PTE_OS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -572,9 +530,7 @@ pte_osResult pte_osSemaphoreCreate(int initialValue, pte_osSemaphoreHandle *pHan
|
|||
char semName[32];
|
||||
|
||||
if (semCtr++ > MAX_PSP_UID)
|
||||
{
|
||||
semCtr = 0;
|
||||
}
|
||||
|
||||
snprintf(semName,sizeof(semName),"pthread_sem%d",semCtr);
|
||||
|
||||
|
@ -612,9 +568,7 @@ pte_osResult pte_osSemaphorePend(pte_osSemaphoreHandle handle, unsigned int *pTi
|
|||
pte_osResult osResult;
|
||||
|
||||
if (pTimeoutMsecs == NULL)
|
||||
{
|
||||
pTimeoutUsecs = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
timeoutUsecs = *pTimeoutMsecs * 1000;
|
||||
|
@ -624,19 +578,12 @@ pte_osResult pte_osSemaphorePend(pte_osSemaphoreHandle handle, unsigned int *pTi
|
|||
result = sceKernelWaitSema(handle, 1, pTimeoutUsecs);
|
||||
|
||||
if (result == SCE_KERNEL_ERROR_OK)
|
||||
{
|
||||
osResult = PTE_OS_OK;
|
||||
}
|
||||
else if (result == SCE_KERNEL_ERROR_WAIT_TIMEOUT)
|
||||
{
|
||||
osResult = PTE_OS_TIMEOUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
osResult = PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
return PTE_OS_OK;
|
||||
|
||||
return osResult;
|
||||
if (result == SCE_KERNEL_ERROR_WAIT_TIMEOUT)
|
||||
return PTE_OS_TIMEOUT;
|
||||
|
||||
return PTE_OS_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -739,9 +686,7 @@ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, uns
|
|||
int pte_osAtomicExchange(int *ptarg, int val)
|
||||
{
|
||||
int intc = pspSdkDisableInterrupts();
|
||||
int origVal;
|
||||
|
||||
origVal = *ptarg;
|
||||
int origVal = *ptarg;
|
||||
|
||||
*ptarg = val;
|
||||
|
||||
|
@ -754,14 +699,10 @@ int pte_osAtomicExchange(int *ptarg, int val)
|
|||
int pte_osAtomicCompareExchange(int *pdest, int exchange, int comp)
|
||||
{
|
||||
int intc = pspSdkDisableInterrupts();
|
||||
int origVal;
|
||||
|
||||
origVal = *pdest;
|
||||
int origVal = *pdest;
|
||||
|
||||
if (*pdest == comp)
|
||||
{
|
||||
*pdest = exchange;
|
||||
}
|
||||
|
||||
pspSdkEnableInterrupts(intc);
|
||||
|
||||
|
@ -771,10 +712,8 @@ int pte_osAtomicCompareExchange(int *pdest, int exchange, int comp)
|
|||
|
||||
int pte_osAtomicExchangeAdd(int volatile* pAddend, int value)
|
||||
{
|
||||
int origVal;
|
||||
int intc = pspSdkDisableInterrupts();
|
||||
|
||||
origVal = *pAddend;
|
||||
int origVal = *pAddend;
|
||||
|
||||
*pAddend += value;
|
||||
|
||||
|
@ -819,12 +758,9 @@ int pte_osAtomicIncrement(int *pdest)
|
|||
|
||||
static pspThreadData *getThreadData(SceUID threadHandle)
|
||||
{
|
||||
pspThreadData *pThreadData;
|
||||
void *pTls;
|
||||
|
||||
pTls = getTlsStructFromThread(threadHandle);
|
||||
|
||||
pThreadData = (pspThreadData *) pteTlsGetValue(pTls, threadDataKey);
|
||||
void *pTls = getTlsStructFromThread(threadHandle);
|
||||
pspThreadData *pThreadData = (pspThreadData *)
|
||||
pteTlsGetValue(pTls, threadDataKey);
|
||||
|
||||
return pThreadData;
|
||||
}
|
||||
|
@ -834,10 +770,8 @@ static void *getTlsStructFromThread(SceUID thid)
|
|||
SceKernelThreadInfo thinfo;
|
||||
unsigned int ptr;
|
||||
unsigned int thrNum;
|
||||
void *pTls;
|
||||
int numMatches;
|
||||
|
||||
|
||||
thinfo.size = sizeof(SceKernelThreadInfo);
|
||||
|
||||
sceKernelReferThreadStatus(thid, &thinfo);
|
||||
|
@ -849,15 +783,9 @@ static void *getTlsStructFromThread(SceUID thid)
|
|||
* "global". This is a pretty bad hack, but necessary due to lack of TLS on PSP.
|
||||
*/
|
||||
if (numMatches == 2)
|
||||
{
|
||||
pTls = (void *) ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pTls = globalTls;
|
||||
}
|
||||
return (void *) ptr;
|
||||
|
||||
return pTls;
|
||||
return globalTls;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -868,19 +796,14 @@ static void *getTlsStructFromThread(SceUID thid)
|
|||
|
||||
pte_osResult pte_osTlsSetValue(unsigned int key, void * value)
|
||||
{
|
||||
void *pTls;
|
||||
|
||||
pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
void *pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
|
||||
return pteTlsSetValue(pTls, key, value);
|
||||
}
|
||||
|
||||
void * pte_osTlsGetValue(unsigned int index)
|
||||
{
|
||||
|
||||
void *pTls;
|
||||
|
||||
pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
void *pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
|
||||
return (void *) pteTlsGetValue(pTls, index);
|
||||
|
||||
|
@ -889,9 +812,7 @@ void * pte_osTlsGetValue(unsigned int index)
|
|||
|
||||
pte_osResult pte_osTlsAlloc(unsigned int *pKey)
|
||||
{
|
||||
void * pTls;
|
||||
|
||||
pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
void *pTls = getTlsStructFromThread(sceKernelGetThreadId());
|
||||
|
||||
return pteTlsAlloc(pKey);
|
||||
|
||||
|
|
|
@ -37,9 +37,6 @@ typedef SceUID pte_osMutexHandle;
|
|||
|
||||
#define OS_IS_HANDLE_VALID(x) ((x) > 0)
|
||||
|
||||
|
||||
|
||||
|
||||
#define OS_MAX_SIMUL_THREADS 10
|
||||
|
||||
#define OS_DEFAULT_PRIO 11
|
||||
|
@ -47,12 +44,12 @@ typedef SceUID pte_osMutexHandle;
|
|||
#define OS_MIN_PRIO 17
|
||||
#define OS_MAX_PRIO 32
|
||||
|
||||
//#define HAVE_THREAD_SAFE_ERRNO
|
||||
#if 0
|
||||
#define HAVE_THREAD_SAFE_ERRNO
|
||||
#endif
|
||||
|
||||
#define POLLING_DELAY_IN_us 100
|
||||
|
||||
|
||||
|
||||
#define OS_MAX_SEM_VALUE 254
|
||||
|
||||
int PspInterlockedExchange(int *ptarg, int val);
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
|
||||
#ifndef _OS_SUPPORT_H_
|
||||
#define _OS_SUPPORT_H_
|
||||
|
||||
// Platform specific one must be included first
|
||||
/* Platform specific one must be included first */
|
||||
#include "psp_osal.h"
|
||||
|
||||
#include "pte_generic_osal.h"
|
||||
|
||||
|
||||
|
||||
#endif // _OS_SUPPORT_H
|
||||
#endif /* _OS_SUPPORT_H */
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <pspsdk.h>
|
||||
#include <pspctrl.h>
|
||||
|
||||
|
||||
PSP_MODULE_INFO("Pthread Test", 0, 1, 1);
|
||||
|
||||
extern void pte_test_main();
|
||||
|
@ -24,10 +23,7 @@ int exit_callback(int arg1, int arg2, void *common)
|
|||
/* Callback thread */
|
||||
int CallbackThread(SceSize args, void *argp)
|
||||
{
|
||||
|
||||
int cbid;
|
||||
|
||||
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
|
||||
int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
|
||||
sceKernelRegisterExitCallback(cbid);
|
||||
|
||||
sceKernelSleepThreadCB();
|
||||
|
@ -38,13 +34,9 @@ int CallbackThread(SceSize args, void *argp)
|
|||
/* Sets up the callback thread and returns its thread id */
|
||||
int SetupCallbacks(void)
|
||||
{
|
||||
int thid = 0;
|
||||
|
||||
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
|
||||
int thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
|
||||
if (thid >= 0)
|
||||
{
|
||||
sceKernelStartThread(thid, 0, 0);
|
||||
}
|
||||
|
||||
return thid;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue