This commit is contained in:
gingerBill
2020-08-02 14:59:51 +01:00
5 changed files with 18 additions and 9 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2016-2017 Ginger Bill. All rights reserved. Copyright (c) 2016-2020 Ginger Bill. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
+6
View File
@@ -83,6 +83,12 @@ file_console_logger_proc :: proc(logger_data: rawptr, level: Level, text: string
do_location_header(options, &buf, location); do_location_header(options, &buf, location);
if .Thread_Id in options {
// NOTE(Oskar): not using context.thread_id here since that could be
// incorrect when replacing context for a thread.
fmt.sbprintf(&buf, "[{}] ", os.current_thread_id());
}
if data.ident != "" do fmt.sbprintf(&buf, "[%s] ", data.ident); if data.ident != "" do fmt.sbprintf(&buf, "[%s] ", data.ident);
//TODO(Hoej): When we have better atomics and such, make this thread-safe //TODO(Hoej): When we have better atomics and such, make this thread-safe
fmt.fprintf(h, "%s %s\n", strings.to_string(buf), text); fmt.fprintf(h, "%s %s\n", strings.to_string(buf), text);
+8 -2
View File
@@ -2,6 +2,7 @@ package os
foreign import dl "system:dl" foreign import dl "system:dl"
foreign import libc "system:c" foreign import libc "system:c"
foreign import pthread "system:pthread"
import "core:runtime" import "core:runtime"
import "core:strings" import "core:strings"
@@ -428,8 +429,13 @@ exit :: inline proc(code: int) -> ! {
} }
current_thread_id :: proc "contextless" () -> int { current_thread_id :: proc "contextless" () -> int {
// return int(_unix_gettid()); tid: u64;
return 0; // NOTE(Oskar): available from OSX 10.6 and iOS 3.2.
// For older versions there is `syscall(SYS_thread_selfid)`, but not really
// the same thing apparently.
foreign pthread { pthread_threadid_np :: proc "c" (rawptr, ^u64) -> c.int ---; }
pthread_threadid_np(nil, &tid);
return int(tid);
} }
dlopen :: inline proc(filename: string, flags: int) -> rawptr { dlopen :: inline proc(filename: string, flags: int) -> rawptr {
+2 -1
View File
@@ -279,7 +279,8 @@ Logger_Option :: enum {
Long_File_Path, Long_File_Path,
Line, Line,
Procedure, Procedure,
Terminal_Color Terminal_Color,
Thread_Id
} }
Logger_Options :: bit_set[Logger_Option]; Logger_Options :: bit_set[Logger_Option];
+1 -5
View File
@@ -14,11 +14,7 @@ PTHREAD_ONCE_SIZE :: 8;
PTHREAD_RWLOCK_SIZE :: 192; PTHREAD_RWLOCK_SIZE :: 192;
PTHREAD_RWLOCKATTR_SIZE :: 16; PTHREAD_RWLOCKATTR_SIZE :: 16;
pthread_t :: opaque struct #align 16 { pthread_t :: opaque u64;
sig: c.long,
cleanup_stack: rawptr,
_: [PTHREAD_SIZE] c.char,
};
pthread_attr_t :: opaque struct #align 16 { pthread_attr_t :: opaque struct #align 16 {
sig: c.long, sig: c.long,