wut/libraries/wutstdc++/wut_gthread_thread.cpp
fincs ee3bb10df4 First pass at adopting a devkitPro-style build system, see details:
- Added wut_rules and wut/rpx/rpl.specs to share/
- Replaced wut's CMake-based buildsystem with a standard Makefile
- Conflated all wut libraries into a single libwut.a library
- wut's old buildsystems (CMake & plain make) are broken as a result,
  this will be fixed in the future
- Docs, tests and samples are not buildable either at the moment
- wutcrt/wutnewlib:
  - RPX start function is __rpx_start, while RPL is __rpl_start
  - __init/fini_wut_* functions are no longer weak
  - __init_wut/__fini_wut are instead weak
  - Removed _exit implementation
  - exit syscall now points to _Exit instead of pointing to itself
- wutstdc++:
  - Renamed .cc files to .cpp
  - Temporarily disabled, due to an issue that will be addressed shortly
- wutdevoptab:
  - Fixed uninitialized variable warnings in __wut_fs_read/write
2019-02-12 12:46:28 +01:00

87 lines
1.7 KiB
C++

#include "wut_gthread.h"
#include <malloc.h>
#include <string.h>
#include <sys/errno.h>
static void
__wut_thread_deallocator(OSThread *thread,
void *stack)
{
free(thread);
free(stack);
}
static void
__wut_thread_cleanup(OSThread *thread, void *stack)
{
__wut_key_cleanup(thread);
}
int
__wut_thread_create(OSThread **outThread,
void *(*entryPoint) (void*),
void *entryArgs)
{
OSThread *thread = (OSThread *)memalign(16, sizeof(OSThread));
char *stack = (char *)memalign(16, __WUT_STACK_SIZE);
memset(thread, 0, sizeof(OSThread));
if (!OSCreateThread(thread,
(OSThreadEntryPointFn)entryPoint,
(int)entryArgs,
NULL,
stack + __WUT_STACK_SIZE,
__WUT_STACK_SIZE,
16,
OS_THREAD_ATTRIB_AFFINITY_ANY)) {
free(thread);
free(stack);
return EINVAL;
}
*outThread = thread;
OSSetThreadDeallocator(thread, &__wut_thread_deallocator);
OSSetThreadCleanupCallback(thread, &__wut_thread_cleanup);
OSResumeThread(thread);
return 0;
}
int
__wut_thread_join(OSThread *thread,
void **outValue)
{
if (!OSJoinThread(thread, (int *)outValue)) {
return EINVAL;
}
return 0;
}
int
__wut_thread_detach(OSThread * thread)
{
OSDetachThread(thread);
return 0;
}
int
__wut_thread_equal(OSThread *thread1,
OSThread *thread2)
{
return thread1 == thread2;
}
OSThread *
__wut_thread_self()
{
return OSGetCurrentThread();
}
int
__wut_thread_yield()
{
OSYieldThread();
return 0;
}