mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
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:
@@ -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")
|
||||
|
||||
@@ -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, ¶ms)
|
||||
assert(res == 0)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user