SDL_threadID SDL_ThreadID(void) { sys_ppu_thread_t id; sysThreadGetId(&id); return ((SDL_threadID) id); }
pte_osResult pte_osTlsSetValue(unsigned int key, void * value) { void *pTls; sys_ppu_thread_t threadId; sysThreadGetId (&threadId); pTls = getTlsStructFromThread(threadId); return pteTlsSetValue(pTls, key, value); }
pte_osResult pte_osTlsAlloc(unsigned int *pKey) { void * pTls; sys_ppu_thread_t threadId; sysThreadGetId (&threadId); pTls = getTlsStructFromThread(threadId); return pteTlsAlloc(pKey); }
void * pte_osTlsGetValue(unsigned int index) { void *pTls; sys_ppu_thread_t threadId; sysThreadGetId (&threadId); pTls = getTlsStructFromThread(threadId); return (void *) pteTlsGetValue(pTls, index); }
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; if (priority == SDL_THREAD_PRIORITY_LOW) { value = 3000; } else if (priority == SDL_THREAD_PRIORITY_HIGH) { value = 1; } else { value = 1500; } sys_ppu_thread_t id; sysThreadGetId(&id); return sysThreadSetPriority(id, value); }
static void thread_start(void *arg) { s32 running = 0; sys_ppu_thread_t id; sys_ppu_thread_stack_t stackinfo; sysThreadGetId(&id); sysThreadGetStackInformation(&stackinfo); printf("stack\naddr: %p, size: %d\n",stackinfo.addr,stackinfo.size); while(running<5) { printf("Thread: %08llX\n",(unsigned long long int)id); sysThreadYield(); sleep(2); running++; } sysThreadExit(0); }
int initSpurs () { int ret; int i; sys_ppu_thread_t ppu_thread_id; int ppu_prio; unsigned int nthread; ret = sysSpuInitialize (6, 0); printf ("sysSpuInitialize return %d\n", ret); ret = sysThreadGetId (&ppu_thread_id); printf ("sysThreadGetId return %d ppu_thread_id %x\n", ret, ppu_thread_id); ret = sysThreadGetPriority (ppu_thread_id, &ppu_prio); printf ("sysThreadGetPriority return %d ppu_prio %d\n", ret, ppu_prio); /* initialize spurs */ printf ("Initializing spurs\n"); spurs = (void *) memalign (SPURS_ALIGN, sizeof (Spurs)); printf ("Initializing spurs attribute\n"); SpursAttribute attributeSpurs; ret = spursAttributeInitialize (&attributeSpurs, 5, 250, ppu_prio - 1, true); if (ret) { printf ("error : spursAttributeInitialize failed %x\n", ret); return (ret); } printf ("Setting name prefix\n"); ret = spursAttributeSetNamePrefix (&attributeSpurs, SPURS_PREFIX_NAME, strlen (SPURS_PREFIX_NAME)); if (ret) { printf ("error : spursAttributeInitialize failed %x\n", ret); return (ret); } printf ("Initializing with attribute\n"); ret = spursInitializeWithAttribute (spurs, &attributeSpurs); if (ret) { printf ("error: spursInitializeWithAttribute failed %x\n", ret); return (ret); } ret = spursGetNumSpuThread (spurs, &nthread); if (ret) { printf ("error: spursGetNumSpuThread failed %x\n", ret); } sys_spu_thread_t *threads = (sys_spu_thread_t *) malloc (sizeof (sys_spu_thread_t) * nthread); ret = spursGetSpuThreadId (spurs, threads, &nthread); if (ret) { printf ("error: spursGetSpuThreadId failed %x\n", ret); } printf ("SPURS %d spu threads availables\n", nthread); for (i = 0; i < nthread; i++) { printf ("SPU Number:%d\tSPU Thread ID:%x\n", i, threads[i]); } printf ("\n"); printf ("checking SpursInfo\n"); SpursInfo info; ret = spursGetInfo (spurs, &info); if (ret) { printf ("error: spursGetInfo failed %x\n", ret); } printf ("SpursInfo: \n"); printf ("nSpus=%d \n", info.nSpus); printf ("spuGroupPriority=%d \n", info.spuGroupPriority); printf ("ppuThreadPriority=%d \n", info.ppuThreadPriority); printf ("exitIfNoWork=%d \n", info.exitIfNoWork); printf ("namePrefix=%s \n", info.namePrefix); for (i = 0; i < info.nSpus; i++) { printf ("SPU Number:%d\tSPU Thread ID:%x\n", i, info.spuThreads[i]); } printf ("SPURS initialized correctly!!!\n"); }
/* * Pend on a semaphore- and allow the pend to be cancelled. * * PS3 OS provides no functionality to asynchronously interrupt a blocked call. We simulte * this by polling on the main semaphore and the cancellation semaphore and sleeping in a loop. */ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, unsigned int *pTimeout) { psl1ghtThreadData *pThreadData; sys_ppu_thread_t threadId; sysThreadGetId (&threadId); pThreadData = getThreadData(threadId); clock_t start_time; s32 result = 0; u64 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) { int status; /* Poll semaphore */ status = sysSemTryWait(semHandle); if (status == 0) { /* User semaphore posted to */ result = PTE_OS_OK; break; } else if ((timeoutEnabled) && ((clock() - start_time) > timeout)) { /* Timeout expired */ result = PTE_OS_TIMEOUT; break; } else { if (pThreadData != NULL) { s32 count; s32 osResult; osResult = sysSemGetValue (pThreadData->cancelSem, &count); if (osResult == 0) { if (count > 0) { result = PTE_OS_INTERRUPTED; break; } else { /* Nothing found and not timed out yet; let's yield so we're not * in busy loop. */ sysThreadYield (); } } else { result = PTE_OS_GENERAL_FAILURE; break; } } } } return result; }
pte_osThreadHandle pte_osThreadGetHandle(void) { pte_osThreadHandle id; sysThreadGetId (&id); return id; }