Skip to content

Commit e6ba62d

Browse files
wiiu: Revise thread creation
1 parent dbdd08e commit e6ba62d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Platform.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,29 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
287287
sceKernelStartThread(thread->handle, sizeof(struct thread_context), ctx);
288288
}
289289
#elif defined(__WIIU__)
290-
int stack_size = 4 * 1024 * 1024;
291-
void* stack_addr = (uint8_t *)memalign(8, stack_size) + stack_size;
290+
memset(&thread->thread, 0, sizeof(thread->thread));
292291

292+
// Allocate stack
293+
const int stack_size = 4 * 1024 * 1024;
294+
uint8_t* stack = (uint8_t*)memalign(16, stack_size);
295+
if (stack == NULL) {
296+
free(ctx);
297+
return -1;
298+
}
299+
300+
// Create thread
293301
if (!OSCreateThread(&thread->thread,
294302
ThreadProc,
295303
0, (char*)ctx,
296-
stack_addr, stack_size,
304+
stack + stack_size, stack_size,
297305
0x10, OS_THREAD_ATTRIB_AFFINITY_ANY))
298306
{
299307
free(ctx);
308+
free(stack);
300309
return -1;
301310
}
302311

312+
OSSetThreadName(&thread->thread, name);
303313
OSSetThreadDeallocator(&thread->thread, thread_deallocator);
304314
OSResumeThread(&thread->thread);
305315
#elif defined(__3DS__)

0 commit comments

Comments
 (0)