diff --git a/LICENSE b/LICENSE index f50c5ada3..e9e75e569 100644 --- a/LICENSE +++ b/LICENSE @@ -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: diff --git a/core/log/file_console_logger.odin b/core/log/file_console_logger.odin index ccecbc8b8..757bb5ff5 100644 --- a/core/log/file_console_logger.odin +++ b/core/log/file_console_logger.odin @@ -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); diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index 9813b9b3b..5300979a1 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -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 { diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 7d1a7bdd5..1ed16d127 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -279,7 +279,8 @@ Logger_Option :: enum { Long_File_Path, Line, Procedure, - Terminal_Color + Terminal_Color, + Thread_Id } Logger_Options :: bit_set[Logger_Option]; diff --git a/core/sys/unix/pthread_darwin.odin b/core/sys/unix/pthread_darwin.odin index 9de64ead4..7f7f59189 100644 --- a/core/sys/unix/pthread_darwin.odin +++ b/core/sys/unix/pthread_darwin.odin @@ -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,