mirror of
https://github.com/pspdev/pspsdk.git
synced 2025-10-03 16:51:27 +00:00
Fix pthread priorities and timeout
This commit is contained in:
@@ -180,6 +180,12 @@ pte_osResult pte_osTerminate(void) {
|
||||
* Threads
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
static inline int invert_priority(int priority)
|
||||
{
|
||||
return (pte_osThreadGetMinPriority() - priority) + pte_osThreadGetMaxPriority();
|
||||
}
|
||||
|
||||
#ifdef F_pte_osThreadCreate
|
||||
pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
|
||||
int stackSize,
|
||||
@@ -255,7 +261,7 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
|
||||
// printf("%s %p %d %d %d\n",threadName, __pspStubThreadEntry, initialPriority, stackSize, pspAttr);
|
||||
threadId = sceKernelCreateThread(threadName,
|
||||
__pspStubThreadEntry,
|
||||
initialPriority,
|
||||
invert_priority(initialPriority),
|
||||
stackSize,
|
||||
pspAttr,
|
||||
NULL);
|
||||
@@ -399,14 +405,14 @@ int pte_osThreadGetPriority(pte_osThreadHandle threadHandle)
|
||||
thinfo.size = sizeof(thinfo);
|
||||
sceKernelReferThreadStatus(threadHandle, &thinfo);
|
||||
|
||||
return thinfo.currentPriority;
|
||||
return invert_priority(thinfo.currentPriority);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef F_pte_osThreadSetPriority
|
||||
pte_osResult pte_osThreadSetPriority(pte_osThreadHandle threadHandle, int newPriority)
|
||||
{
|
||||
sceKernelChangeThreadPriority(threadHandle, newPriority);
|
||||
sceKernelChangeThreadPriority(threadHandle, invert_priority(newPriority));
|
||||
return PTE_OS_OK;
|
||||
}
|
||||
#endif
|
||||
@@ -475,21 +481,21 @@ void pte_osThreadSleep(unsigned int msecs)
|
||||
#ifdef F_pte_osThreadGetMinPriority
|
||||
int pte_osThreadGetMinPriority()
|
||||
{
|
||||
return 17;
|
||||
return pte_osThreadGetDefaultPriority() - 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef F_pte_osThreadGetMaxPriority
|
||||
int pte_osThreadGetMaxPriority()
|
||||
{
|
||||
return 30;
|
||||
return pte_osThreadGetDefaultPriority() + 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef F_pte_osThreadGetDefaultPriority
|
||||
int pte_osThreadGetDefaultPriority()
|
||||
{
|
||||
return 18;
|
||||
return 60;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -621,7 +627,7 @@ pte_osResult pte_osSemaphorePend(pte_osSemaphoreHandle handle, unsigned int *pTi
|
||||
{
|
||||
unsigned int timeoutUsecs;
|
||||
unsigned int *pTimeoutUsecs;
|
||||
SceUInt result;
|
||||
int result;
|
||||
pte_osResult osResult;
|
||||
|
||||
if (pTimeoutMsecs == NULL) {
|
||||
@@ -661,17 +667,14 @@ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, uns
|
||||
clock_t start_time;
|
||||
pte_osResult result = PTE_OS_OK;
|
||||
unsigned int timeout;
|
||||
unsigned char timeoutEnabled;
|
||||
|
||||
start_time = clock();
|
||||
|
||||
// clock() is in microseconds, timeout as passed in was in milliseconds
|
||||
if (pTimeout == NULL) {
|
||||
timeout = 0;
|
||||
timeoutEnabled = 0;
|
||||
} else {
|
||||
timeout = *pTimeout * 1000;
|
||||
timeoutEnabled = 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
@@ -686,7 +689,7 @@ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, uns
|
||||
/* User semaphore posted to */
|
||||
result = PTE_OS_OK;
|
||||
break;
|
||||
} else if ((timeoutEnabled) && ((clock() - start_time) > timeout)) {
|
||||
} else if ((pTimeout) && ((clock() - start_time) > timeout)) {
|
||||
/* Timeout expired */
|
||||
result = PTE_OS_TIMEOUT;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user