Browse Source

Merge branch 'master' of https://github.com/odin-lang/Odin

gingerBill 5 years ago
parent
commit
16abfd56e8

+ 1 - 1
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:

+ 6 - 0
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);

+ 8 - 2
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 {

+ 2 - 1
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];

+ 1 - 5
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,