some refactoring on thread class

This commit is contained in:
georgemoralis 2023-11-10 20:51:02 +02:00
parent 91885e8a41
commit a10af46153
2 changed files with 13 additions and 22 deletions

View File

@ -58,17 +58,14 @@ int PS4_SYSV_ABI scePthreadAttrSetdetachstate(ScePthreadAttr* attr, int detachst
switch (detachstate) { switch (detachstate) {
case 0: pstate = PTHREAD_CREATE_JOINABLE; break; case 0: pstate = PTHREAD_CREATE_JOINABLE; break;
case 1: pstate = PTHREAD_CREATE_DETACHED; break; case 1: pstate = PTHREAD_CREATE_DETACHED; break;
default: BREAKPOINT(); // unknown state default: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetdetachstate invalid detachstate: {}\n", detachstate); std::exit(0);
} }
int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate); int result = pthread_attr_setdetachstate(&(*attr)->pth_attr, pstate);
(*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED); (*attr)->detached = (pstate == PTHREAD_CREATE_DETACHED);
if (result == 0) { return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
return SCE_OK;
}
return SCE_KERNEL_ERROR_EINVAL;
} }
int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) { int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inheritSched) {
@ -80,15 +77,12 @@ int PS4_SYSV_ABI scePthreadAttrSetinheritsched(ScePthreadAttr* attr, int inherit
switch (inheritSched) { switch (inheritSched) {
case 0: pinherit_sched = PTHREAD_EXPLICIT_SCHED; break; case 0: pinherit_sched = PTHREAD_EXPLICIT_SCHED; break;
case 4: pinherit_sched = PTHREAD_INHERIT_SCHED; break; case 4: pinherit_sched = PTHREAD_INHERIT_SCHED; break;
default: BREAKPOINT(); // unknown inheritSched default: LOG_TRACE_IF(log_pthread_file, "scePthreadAttrSetinheritsched invalid inheritSched: {}\n", inheritSched); std::exit(0);
} }
int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched); int result = pthread_attr_setinheritsched(&(*attr)->pth_attr, pinherit_sched);
if (result == 0) { return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
return SCE_OK;
}
return SCE_KERNEL_ERROR_EINVAL;
} }
int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) { int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKernelSchedParam* param) {
@ -107,10 +101,7 @@ int PS4_SYSV_ABI scePthreadAttrSetschedparam(ScePthreadAttr* attr, const SceKern
int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam); int result = pthread_attr_setschedparam(&(*attr)->pth_attr, &pparam);
if (result == 0) { return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
return SCE_OK;
}
return SCE_KERNEL_ERROR_EINVAL;
} }
int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) { int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy) {
@ -118,18 +109,13 @@ int PS4_SYSV_ABI scePthreadAttrSetschedpolicy(ScePthreadAttr* attr, int policy)
return SCE_KERNEL_ERROR_EINVAL; return SCE_KERNEL_ERROR_EINVAL;
} }
if (policy != SCHED_OTHER) { int ppolicy = SCHED_OTHER; // winpthreads only supports SCHED_OTHER
BREAKPOINT(); // invest if policy is other and if winpthreadlibrary support it
}
(*attr)->policy = policy; (*attr)->policy = policy;
int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, policy); int result = pthread_attr_setschedpolicy(&(*attr)->pth_attr, policy);
if (result == 0) { return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL;
return SCE_OK;
}
return SCE_KERNEL_ERROR_EINVAL;
} }
/**** /****
@ -222,6 +208,11 @@ void pthreadSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit); LIB_FUNCTION("F8bUHwAG284", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrInit);
LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype); LIB_FUNCTION("iMp8QpE+XO4", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSettype);
LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol); LIB_FUNCTION("1FGvU0i9saQ", "libkernel", 1, "libkernel", 1, 1, scePthreadMutexattrSetprotocol);
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedpolicy);
LIB_FUNCTION("-Wreprtu0Qs", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetdetachstate);
LIB_FUNCTION("eXbUSpEaTsA", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetinheritsched);
LIB_FUNCTION("DzES9hQF4f4", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrSetschedparam);
LIB_FUNCTION("nsYoNRywwNg", "libkernel", 1, "libkernel", 1, 1, scePthreadAttrInit);
// posix calls // posix calls
LIB_FUNCTION("ttHNfU+qDBU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_init); LIB_FUNCTION("ttHNfU+qDBU", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_mutex_init);
} }

View File

@ -654,7 +654,7 @@ static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func)
} }
void Linker::Execute() { void Linker::Execute() {
Core::Kernel::Pthread_Init_Self_MainThread(); Core::Libraries::LibKernel::Pthread_Init_Self_MainThread();
EntryParams p{}; EntryParams p{};
p.argc = 1; p.argc = 1;
p.argv[0] = "eboot.bin"; //hmm should be ok? p.argv[0] = "eboot.bin"; //hmm should be ok?