The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #13504 from toots/thread-name

Add thread set_name API.

authored by

Gabriel Scherer and committed by
GitHub
ad2aecfa e026d942

+180
+3
Changes
··· 89 89 default environment (where `TEMP` is set), there is no discernible change. 90 90 (Antonin Décimo, review by Nicolás Ojeda Bär and David Allsopp) 91 91 92 + - #13504: Add `Thread.set_current_thread_name`. 93 + (Romain Beauxis, review by Gabriel Scherer and Antonin Décimo) 94 + 92 95 ### Tools: 93 96 94 97 - #12019: ocamlc: add `align_double` and `align_int64` to `ocamlc -config`
+61
configure
··· 20252 20252 rm -f core conftest.err conftest.$ac_objext conftest.beam \ 20253 20253 conftest$ac_exeext conftest.$ac_ext 20254 20254 20255 + ## prctl 20256 + ac_fn_check_decl "$LINENO" "prctl" "ac_cv_have_decl_prctl" "#include <sys/prctl.h> 20257 + " "$ac_c_undeclared_builtin_options" "CFLAGS" 20258 + if test "x$ac_cv_have_decl_prctl" = xyes 20259 + then : 20260 + printf "%s\n" "#define HAS_DECL_PRCTL 1" >>confdefs.h 20261 + 20262 + fi 20263 + 20264 + ## pthread_setname_np 20265 + 20266 + for ac_func in pthread_setname_np 20267 + do : 20268 + ac_fn_c_check_func "$LINENO" "pthread_setname_np" "ac_cv_func_pthread_setname_np" 20269 + if test "x$ac_cv_func_pthread_setname_np" = xyes 20270 + then : 20271 + printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h 20272 + printf "%s\n" "#define HAS_PTHREAD_SETNAME_NP 1" >>confdefs.h 20273 + 20274 + fi 20275 + 20276 + done 20277 + 20278 + ## pthread_set_name_np 20279 + 20280 + for ac_func in pthread_set_name_np 20281 + do : 20282 + ac_fn_c_check_func "$LINENO" "pthread_set_name_np" "ac_cv_func_pthread_set_name_np" 20283 + if test "x$ac_cv_func_pthread_set_name_np" = xyes 20284 + then : 20285 + printf "%s\n" "#define HAVE_PTHREAD_SET_NAME_NP 1" >>confdefs.h 20286 + printf "%s\n" "#define HAS_PTHREAD_SET_NAME_NP 1" >>confdefs.h 20287 + 20288 + fi 20289 + 20290 + done 20291 + 20292 + ## SetThreadDescription 20293 + 20294 + for ac_func in SetThreadDescription 20295 + do : 20296 + ac_fn_c_check_func "$LINENO" "SetThreadDescription" "ac_cv_func_SetThreadDescription" 20297 + if test "x$ac_cv_func_SetThreadDescription" = xyes 20298 + then : 20299 + printf "%s\n" "#define HAVE_SETTHREADDESCRIPTION 1" >>confdefs.h 20300 + printf "%s\n" "#define HAS_SETTHREADDESCRIPTION 1" >>confdefs.h 20301 + 20302 + fi 20303 + 20304 + done 20305 + 20306 + ac_fn_check_decl "$LINENO" "SetThreadDescription" "ac_cv_have_decl_SetThreadDescription" "#define WIN32_LEAN_AND_MEAN 20307 + #include <windows.h> 20308 + #include <processthreadsapi.h> 20309 + " "$ac_c_undeclared_builtin_options" "CFLAGS" 20310 + if test "x$ac_cv_have_decl_SetThreadDescription" = xyes 20311 + then : 20312 + printf "%s\n" "#define HAS_DECL_SETTHREADDESCRIPTION 1" >>confdefs.h 20313 + 20314 + fi 20315 + 20255 20316 ## Activate the systhread library 20256 20317 20257 20318 case $enable_systhreads,$enable_unix_lib in #(
+30
configure.ac
··· 2419 2419 AC_DEFINE([HAS_BSD_GETAFFINITY_NP], [1])], 2420 2420 [AC_MSG_RESULT([pthread_getaffinity_np not found])])]) 2421 2421 2422 + ## prctl 2423 + AC_CHECK_DECL( 2424 + [prctl], 2425 + [AC_DEFINE([HAS_DECL_PRCTL] , [1])], 2426 + [], 2427 + [#include <sys/prctl.h>]) 2428 + 2429 + ## pthread_setname_np 2430 + AC_CHECK_FUNCS( 2431 + [pthread_setname_np], 2432 + [AC_DEFINE([HAS_PTHREAD_SETNAME_NP], [1])]) 2433 + 2434 + ## pthread_set_name_np 2435 + AC_CHECK_FUNCS( 2436 + [pthread_set_name_np], 2437 + [AC_DEFINE([HAS_PTHREAD_SET_NAME_NP], [1])]) 2438 + 2439 + ## SetThreadDescription 2440 + AC_CHECK_FUNCS( 2441 + [SetThreadDescription], 2442 + [AC_DEFINE([HAS_SETTHREADDESCRIPTION], [1])]) 2443 + 2444 + AC_CHECK_DECL( 2445 + [SetThreadDescription], 2446 + [AC_DEFINE([HAS_DECL_SETTHREADDESCRIPTION], [1])], 2447 + [], 2448 + [[#define WIN32_LEAN_AND_MEAN 2449 + #include <windows.h> 2450 + #include <processthreadsapi.h>]]) 2451 + 2422 2452 ## Activate the systhread library 2423 2453 2424 2454 AS_CASE([$enable_systhreads,$enable_unix_lib],
+64
otherlibs/systhreads/st_stubs.c
··· 15 15 16 16 #define CAML_INTERNALS 17 17 18 + #define _GNU_SOURCE /* helps to find pthread_setname_np() */ 19 + #include "caml/config.h" 20 + 21 + #if defined(_WIN32) 22 + # include <windows.h> 23 + # include <processthreadsapi.h> 24 + # include <caml/osdeps.h> 25 + 26 + # if defined(HAS_SETTHREADDESCRIPTION) && \ 27 + !defined(HAS_DECL_SETTHREADDESCRIPTION) 28 + HRESULT SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription); 29 + # endif 30 + 31 + #elif defined(HAS_DECL_PRCTL) 32 + # include <sys/prctl.h> 33 + #elif defined(HAS_PTHREAD_SETNAME_NP) || defined(HAS_PTHREAD_SET_NAME_NP) 34 + # include <pthread.h> 35 + 36 + # if defined(HAS_PTHREAD_NP_H) 37 + # include <pthread_np.h> 38 + # endif 39 + #endif 40 + 41 + #include "caml/misc.h" 42 + 18 43 #if defined(_WIN32) && !defined(NATIVE_CODE) && !defined(_MSC_VER) 19 44 /* Ensure that pthread.h marks symbols __declspec(dllimport) so that they can be 20 45 picked up from the runtime (which will have linked winpthreads statically). ··· 951 976 952 977 CAMLreturnT(st_retcode, retcode); 953 978 } 979 + 980 + /* Set the current thread's name. */ 981 + CAMLprim value caml_set_current_thread_name(value name) 982 + { 983 + #if defined(_WIN32) 984 + 985 + # if defined(HAS_SETTHREADDESCRIPTION) 986 + wchar_t *thread_name = caml_stat_strdup_to_utf16(String_val(name)); 987 + SetThreadDescription(GetCurrentThread(), thread_name); 988 + caml_stat_free(thread_name); 989 + # endif 990 + 991 + # if defined(HAS_PTHREAD_SETNAME_NP) 992 + // We are using both methods. 993 + // See: https://github.com/ocaml/ocaml/pull/13504#discussion_r1786358928 994 + pthread_setname_np(pthread_self(), String_val(name)); 995 + # endif 996 + 997 + #elif defined(HAS_DECL_PRCTL) 998 + prctl(PR_SET_NAME, String_val(name)); 999 + #elif defined(HAS_PTHREAD_SETNAME_NP) 1000 + # if defined(__APPLE__) 1001 + pthread_setname_np(String_val(name)); 1002 + # elif defined(__NetBSD__) 1003 + pthread_setname_np(pthread_self(), "%s", String_val(name)); 1004 + # else 1005 + pthread_setname_np(pthread_self(), String_val(name)); 1006 + # endif 1007 + #elif defined(HAS_PTHREAD_SET_NAME_NP) 1008 + pthread_set_name_np(pthread_self(), String_val(name)); 1009 + #else 1010 + if (caml_runtime_warnings_active()) { 1011 + fprintf(stderr, "set thread name not implemented\n"); 1012 + fflush(stderr); 1013 + } 1014 + #endif 1015 + 1016 + return Val_unit; 1017 + }
+3
otherlibs/systhreads/thread.ml
··· 92 92 93 93 let sigmask = Unix.sigprocmask 94 94 let wait_signal = Unix.sigwait 95 + 96 + external set_current_thread_name : string -> unit = 97 + "caml_set_current_thread_name"
+9
otherlibs/systhreads/thread.mli
··· 45 45 is an integer that identifies uniquely the thread. 46 46 It can be used to build data structures indexed by threads. *) 47 47 48 + val set_current_thread_name : string -> unit 49 + (** Set the thread's name. This should be called from within the thread 50 + function. Setting thread name is available on most systems. 51 + 52 + This does nothing if the functionality is not implemented but will 53 + print a warning on the standard error if enabled. 54 + 55 + @since 5.4 *) 56 + 48 57 exception Exit 49 58 (** Exception raised by user code to initiate termination of the 50 59 current thread.
+10
runtime/caml/s.h.in
··· 108 108 109 109 #undef HAS_PTHREAD_NP_H 110 110 111 + #undef HAS_DECL_PRCTL 112 + 113 + #undef HAS_PTHREAD_SETNAME_NP 114 + 115 + #undef HAS_PTHREAD_SET_NAME_NP 116 + 117 + #undef HAS_SETTHREADDESCRIPTION 118 + 119 + #undef HAS_DECL_SETTHREADDESCRIPTION 120 + 111 121 #undef HAS_UNISTD 112 122 113 123 /* Define HAS_UNISTD if you have /usr/include/unistd.h. */