This commit is contained in:
gingerBill
2020-08-02 14:59:51 +01:00
5 changed files with 18 additions and 9 deletions

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
modification, are permitted provided that the following conditions are met:

View File

@@ -83,6 +83,12 @@ file_console_logger_proc :: proc(logger_data: rawptr, level: Level, text: string
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);
//TODO(Hoej): When we have better atomics and such, make this thread-safe
fmt.fprintf(h, "%s %s\n", strings.to_string(buf), text);

View File

@@ -2,6 +2,7 @@ package os
foreign import dl "system:dl"
foreign import libc "system:c"
foreign import pthread "system:pthread"
import "core:runtime"
import "core:strings"
@@ -428,8 +429,13 @@ exit :: inline proc(code: int) -> ! {
}
current_thread_id :: proc "contextless" () -> int {
// return int(_unix_gettid());
return 0;
tid: u64;
// 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 {

View File

@@ -279,7 +279,8 @@ Logger_Option :: enum {
Long_File_Path,
Line,
Procedure,
Terminal_Color
Terminal_Color,
Thread_Id
}
Logger_Options :: bit_set[Logger_Option];

View File

@@ -14,11 +14,7 @@ PTHREAD_ONCE_SIZE :: 8;
PTHREAD_RWLOCK_SIZE :: 192;
PTHREAD_RWLOCKATTR_SIZE :: 16;
pthread_t :: opaque struct #align 16 {
sig: c.long,
cleanup_stack: rawptr,
_: [PTHREAD_SIZE] c.char,
};
pthread_t :: opaque u64;
pthread_attr_t :: opaque struct #align 16 {
sig: c.long,