MCPcopy Create free account
hub / github.com/cemu-project/Cemu / __OSThreadInit

Function __OSThreadInit

src/Cafe/OS/libs/coreinit/coreinit_Thread.cpp:263–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261 }
262
263 void __OSThreadInit(OSThread_t* thread, MEMPTR<void> entrypoint, uint32 argInt, MEMPTR<void> argPtr, MEMPTR<void> stackTop, uint32 stackSize, sint32 priority, uint32 upirCoreIndex, OSThread_t::THREAD_TYPE threadType)
264 {
265 thread->effectivePriority = priority;
266 thread->type = threadType;
267 thread->basePriority = priority;
268 thread->SetThreadMagic();
269 thread->id = 0x8000;
270 thread->waitAlarm = nullptr;
271 thread->entrypoint = entrypoint;
272 thread->quantumTicks = 0;
273 if(entrypoint)
274 {
275 thread->state = OSThread_t::THREAD_STATE::STATE_READY;
276 thread->suspendCounter = 1;
277 }
278 else
279 {
280 thread->state = OSThread_t::THREAD_STATE::STATE_NONE;
281 thread->suspendCounter = 0;
282 }
283 thread->exitValue = (uint32)-1;
284 thread->requestFlags = OSThread_t::REQUEST_FLAG_BIT::REQUEST_FLAG_NONE;
285 thread->pendingSuspend = 0;
286 thread->suspendResult = 0xFFFFFFFF;
287 thread->coretimeSumQuantumStart = 0;
288 thread->deallocatorFunc = nullptr;
289 thread->cleanupCallback = nullptr;
290 thread->waitingForFastMutex = nullptr;
291 thread->stateFlags = 0;
292 thread->waitingForMutex = nullptr;
293 memset(&thread->crt, 0, sizeof(thread->crt));
294 static_assert(sizeof(thread->crt) == 0x1D8);
295 thread->tlsBlocksMPTR = 0;
296 thread->numAllocatedTLSBlocks = 0;
297 thread->tlsStatus = 0;
298 OSInitThreadQueueEx(&thread->joinQueue, thread);
299 OSInitThreadQueueEx(&thread->suspendQueue, thread);
300 thread->mutexQueue.ukn08 = thread;
301 thread->mutexQueue.ukn0C = 0;
302 thread->mutexQueue.tail = nullptr;
303 thread->mutexQueue.head = nullptr;
304 thread->ownedFastMutex.next = nullptr;
305 thread->ownedFastMutex.prev = nullptr;
306 thread->contendedFastMutex.next = nullptr;
307 thread->contendedFastMutex.prev = nullptr;
308
309 MEMPTR<void> alignedStackTop{MEMPTR<void>(stackTop).GetMPTR() & 0xFFFFFFF8};
310 MEMPTR<uint32be> alignedStackTop32{alignedStackTop};
311 alignedStackTop32[-1] = 0;
312 alignedStackTop32[-2] = 0;
313
314 __OSInitContext(&thread->context, MEMPTR<void>(PPCInterpreter_makeCallableExportDepr(threadEntry)), (void*)(alignedStackTop32.GetPtr() - 2));
315 thread->stackBase = stackTop; // without alignment
316 thread->stackEnd = ((uint8*)stackTop.GetPtr() - stackSize);
317 thread->context.upir = upirCoreIndex;
318 thread->context.lr = _swapEndianU32(PPCInterpreter_makeCallableExportDepr(coreinitExport_OSExitThreadDepr));
319 thread->context.gpr[3] = _swapEndianU32(argInt);
320 thread->context.gpr[4] = _swapEndianU32(argPtr.GetMPTR());

Callers 1

Calls 7

OSInitThreadQueueExFunction · 0.85
__OSInitContextFunction · 0.85
_swapEndianU32Function · 0.85
SetThreadMagicMethod · 0.80
GetMPTRMethod · 0.45
GetPtrMethod · 0.45

Tested by

no test coverage detected