[前][次][番号順一覧][スレッド一覧]

ruby-changes:71935

From: Koichi <ko1@a...>
Date: Tue, 24 May 2022 10:07:23 +0900 (JST)
Subject: [ruby-changes:71935] f3235ac095 (master): add `rb_th_serial()`

https://git.ruby-lang.org/ruby.git/commit/?id=f3235ac095

From f3235ac09582c764086da28245a86753a100ba58 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Tue, 24 May 2022 03:57:06 +0900
Subject: add `rb_th_serial()`

`rb_th_serial(th)` returns th's serial for debug print purpose.
---
 debug.c   | 2 +-
 vm_core.h | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/debug.c b/debug.c
index 3a6caca58a..6c9d6563db 100644
--- a/debug.c
+++ b/debug.c
@@ -474,7 +474,7 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm https://github.com/ruby/ruby/blob/trunk/debug.c#L474
         // thread information
         const rb_thread_t *th = GET_THREAD();
         if (r && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
-            r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", (unsigned int)th->serial);
+            r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN - len, "\tth:%u", rb_th_serial(th));
             if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
             len += r;
         }
diff --git a/vm_core.h b/vm_core.h
index 4de0777292..58fb1e7e3b 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -1078,6 +1078,12 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1078
 #endif
 } rb_thread_t;
 
+static inline unsigned int
+rb_th_serial(const rb_thread_t *th)
+{
+    return (unsigned int)th->serial;
+}
+
 typedef enum {
     VM_DEFINECLASS_TYPE_CLASS           = 0x00,
     VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]