fix core:thread and a memory leak

in the future probably native non-pthread implementation for haiku will be required
This commit is contained in:
avanspector
2024-02-27 02:38:06 +01:00
parent 38c69b9691
commit fca691a066
3 changed files with 22 additions and 17 deletions
+11 -7
View File
@@ -33,15 +33,9 @@ foreign pthread {
pthread_attr_getschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
pthread_attr_setschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
pthread_attr_getschedpolicy :: proc(t: ^pthread_attr_t, policy: ^c.int) -> c.int ---
pthread_attr_setschedpolicy :: proc(t: ^pthread_attr_t, policy: c.int) -> c.int ---
// states: PTHREAD_CREATE_DETACHED, PTHREAD_CREATE_JOINABLE
pthread_attr_setdetachstate :: proc(attrs: ^pthread_attr_t, detach_state: c.int) -> c.int ---
// scheds: PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED
pthread_attr_setinheritsched :: proc(attrs: ^pthread_attr_t, sched: c.int) -> c.int ---
// NOTE(tetra, 2019-11-06): WARNING: Different systems have different alignment requirements.
// For maximum usefulness, use the OS's page size.
// ALSO VERY MAJOR WARNING: `stack_ptr` must be the LAST byte of the stack on systems
@@ -57,7 +51,17 @@ foreign pthread {
pthread_sigmask :: proc(how: c.int, set: rawptr, oldset: rawptr) -> c.int ---
sched_yield :: proc() -> c.int ---
}
// NOTE: Unimplemented in Haiku.
when ODIN_OS != .Haiku {
foreign pthread {
// scheds: PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED
pthread_attr_setinheritsched :: proc(attrs: ^pthread_attr_t, sched: c.int) -> c.int ---
pthread_attr_getschedpolicy :: proc(t: ^pthread_attr_t, policy: ^c.int) -> c.int ---
pthread_attr_setschedpolicy :: proc(t: ^pthread_attr_t, policy: c.int) -> c.int ---
}
}
@(default_calling_convention="c")
+9 -4
View File
@@ -1,4 +1,4 @@
// +build linux, darwin, freebsd, openbsd
// +build linux, darwin, freebsd, openbsd, haiku
// +private
package thread
@@ -78,7 +78,9 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
// NOTE(tetra, 2019-11-01): These only fail if their argument is invalid.
assert(unix.pthread_attr_setdetachstate(&attrs, unix.PTHREAD_CREATE_JOINABLE) == 0)
assert(unix.pthread_attr_setinheritsched(&attrs, unix.PTHREAD_EXPLICIT_SCHED) == 0)
when ODIN_OS != .Haiku {
assert(unix.pthread_attr_setinheritsched(&attrs, unix.PTHREAD_EXPLICIT_SCHED) == 0)
}
thread := new(Thread)
if thread == nil {
@@ -88,8 +90,11 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread {
// Set thread priority.
policy: i32
res := unix.pthread_attr_getschedpolicy(&attrs, &policy)
assert(res == 0)
res: i32
when ODIN_OS != .Haiku {
res = unix.pthread_attr_getschedpolicy(&attrs, &policy)
assert(res == 0)
}
params: unix.sched_param
res = unix.pthread_attr_getschedparam(&attrs, &params)
assert(res == 0)
+2 -6
View File
@@ -898,6 +898,7 @@ gb_internal String internal_odin_root_dir(void) {
}
auto path_buf = array_make<char>(heap_allocator(), 300);
defer (array_free(&path_buf));
len = 0;
for (;;) {
@@ -930,9 +931,6 @@ gb_internal String internal_odin_root_dir(void) {
global_module_path = path;
global_module_path_set = true;
// array_free(&path_buf);
return path;
}
@@ -952,6 +950,7 @@ gb_internal String internal_odin_root_dir(void) {
}
auto path_buf = array_make<char>(heap_allocator(), 300);
defer (array_free(&path_buf));
len = 0;
for (;;) {
@@ -984,9 +983,6 @@ gb_internal String internal_odin_root_dir(void) {
global_module_path = path;
global_module_path_set = true;
// array_free(&path_buf);
return path;
}
#else