aboutsummaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-26 00:30:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-26 00:30:03 +0000
commit35e315c9dc7a97894b498afb75ce859776b80e54 (patch)
tree123927bc19e68863da3b0ba2a1fb8c0bbed106de /win32
parent4c845b30e84dd22d5c3507545f48ad95de65b585 (diff)
downloadruby-35e315c9dc7a97894b498afb75ce859776b80e54.tar.gz
thread_win32.c: set thread name
* thread_win32.c (native_set_another_thread_name): set thread name by SetThreadDescription. * win32/win32.c (rb_w32_set_thread_description): dynamically try SetThreadDescription. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index d40f0a57b1..9243d6a293 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -7857,6 +7857,48 @@ rb_w32_pow(double x, double y)
}
#endif
+int
+rb_w32_set_thread_description(HANDLE th, const WCHAR *name)
+{
+ int result = FALSE;
+ typedef HRESULT (WINAPI *set_thread_description_func)(HANDLE, PCWSTR);
+ static set_thread_description_func set_thread_description =
+ (set_thread_description_func)-1;
+ if (set_thread_description == (set_thread_description_func)-1) {
+ set_thread_description = (set_thread_description_func)
+ get_proc_address("kernel32", "SetThreadDescription", NULL);
+ }
+ if (set_thread_description != (set_thread_description_func)-1) {
+ result = set_thread_description(th, name);
+ }
+ return result;
+}
+
+int
+rb_w32_set_thread_description_str(HANDLE th, VALUE name)
+{
+ int idx, result = FALSE;
+ WCHAR *s;
+
+ if (NIL_P(name)) {
+ rb_w32_set_thread_description(th, L"");
+ return;
+ }
+ s = (WCHAR *)StringValueCStr(name);
+ idx = rb_enc_get_index(name);
+ if (idx == ENCINDEX_UTF_16LE) {
+ result = rb_w32_set_thread_description(th, s);
+ }
+ else {
+ name = rb_str_conv_enc(name, rb_enc_from_index(idx), rb_utf8_encoding());
+ s = mbstr_to_wstr(CP_UTF8, RSTRING_PTR(name), RSTRING_LEN(name)+1, NULL);
+ result = rb_w32_set_thread_description(th, s);
+ free(s);
+ }
+ RB_GC_GUARD(name);
+ return result;
+}
+
VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE) = rb_f_notimplement;
#if RUBY_MSVCRT_VERSION < 120