mirror of https://gitlab.com/nakst/essence
put ThreadLocalStorage on the stack
This commit is contained in:
parent
be6d633223
commit
43c3a69560
|
@ -136,6 +136,8 @@ struct {
|
||||||
#define PERFORMANCE_TIMER_STACK_SIZE (100)
|
#define PERFORMANCE_TIMER_STACK_SIZE (100)
|
||||||
uint64_t performanceTimerStack[PERFORMANCE_TIMER_STACK_SIZE];
|
uint64_t performanceTimerStack[PERFORMANCE_TIMER_STACK_SIZE];
|
||||||
uintptr_t performanceTimerStackCount;
|
uintptr_t performanceTimerStackCount;
|
||||||
|
|
||||||
|
ThreadLocalStorage firstThreadLocalStorage;
|
||||||
} api;
|
} api;
|
||||||
|
|
||||||
ptrdiff_t tlsStorageOffset;
|
ptrdiff_t tlsStorageOffset;
|
||||||
|
@ -1074,11 +1076,8 @@ uint64_t EsSystemGetConstant(uintptr_t index) {
|
||||||
return api.systemConstants[index];
|
return api.systemConstants[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadInitialise() {
|
void ThreadInitialise(ThreadLocalStorage *local) {
|
||||||
// TODO Memory leak: this structure is never freed.
|
EsMemoryZero(local, sizeof(ThreadLocalStorage));
|
||||||
// Perhaps the kernel should send a message when a user thread is terminated to its owner process?
|
|
||||||
|
|
||||||
ThreadLocalStorage *local = (ThreadLocalStorage *) EsHeapAllocate(sizeof(ThreadLocalStorage), true);
|
|
||||||
local->id = EsSyscall(ES_SYSCALL_THREAD_GET_ID, ES_CURRENT_THREAD, 0, 0, 0);
|
local->id = EsSyscall(ES_SYSCALL_THREAD_GET_ID, ES_CURRENT_THREAD, 0, 0, 0);
|
||||||
local->self = local;
|
local->self = local;
|
||||||
EsSyscall(ES_SYSCALL_PROCESS_SET_TLS, (uintptr_t) local - tlsStorageOffset, 0, 0, 0);
|
EsSyscall(ES_SYSCALL_PROCESS_SET_TLS, (uintptr_t) local - tlsStorageOffset, 0, 0, 0);
|
||||||
|
@ -1105,7 +1104,7 @@ extern "C" void _start(EsProcessStartupInformation *_startupInformation) {
|
||||||
_init();
|
_init();
|
||||||
EsSyscall(ES_SYSCALL_SYSTEM_GET_CONSTANTS, (uintptr_t) api.systemConstants, 0, 0, 0);
|
EsSyscall(ES_SYSCALL_SYSTEM_GET_CONSTANTS, (uintptr_t) api.systemConstants, 0, 0, 0);
|
||||||
EsRandomSeed(EsTimeStamp());
|
EsRandomSeed(EsTimeStamp());
|
||||||
ThreadInitialise();
|
ThreadInitialise(&api.firstThreadLocalStorage);
|
||||||
EsMessageMutexAcquire();
|
EsMessageMutexAcquire();
|
||||||
|
|
||||||
api.global = (GlobalData *) EsObjectMap(EsMemoryOpen(sizeof(GlobalData), EsLiteral("Desktop.Global"), ES_FLAGS_DEFAULT),
|
api.global = (GlobalData *) EsObjectMap(EsMemoryOpen(sizeof(GlobalData), EsLiteral("Desktop.Global"), ES_FLAGS_DEFAULT),
|
||||||
|
|
|
@ -105,10 +105,11 @@ int EsProcessGetExitStatus(EsHandle process) {
|
||||||
return EsSyscall(ES_SYSCALL_PROCESS_GET_STATUS, process, 0, 0, 0);
|
return EsSyscall(ES_SYSCALL_PROCESS_GET_STATUS, process, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadInitialise();
|
void ThreadInitialise(ThreadLocalStorage *local);
|
||||||
|
|
||||||
void ThreadEntry(EsGeneric argument, EsThreadEntryFunction entryFunction) {
|
void ThreadEntry(EsGeneric argument, EsThreadEntryFunction entryFunction) {
|
||||||
ThreadInitialise();
|
ThreadLocalStorage local;
|
||||||
|
ThreadInitialise(&local);
|
||||||
entryFunction(argument);
|
entryFunction(argument);
|
||||||
EsThreadTerminate(ES_CURRENT_THREAD);
|
EsThreadTerminate(ES_CURRENT_THREAD);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue