diff options
| author | 2025-06-07 09:40:41 -0400 | |
|---|---|---|
| committer | 2025-06-07 09:41:14 -0400 | |
| commit | 393e266f6bfceb25a97cd1cf28dfc72cac9e9f81 (patch) | |
| tree | 04d98242dcfaac5365f434e0571cebf513683046 | |
| parent | 6993b9814769668fb03b4d282734f20f63b16f9c (diff) | |
| download | libnaunet-393e266f6bfceb25a97cd1cf28dfc72cac9e9f81.tar.gz libnaunet-393e266f6bfceb25a97cd1cf28dfc72cac9e9f81.tar.bz2 libnaunet-393e266f6bfceb25a97cd1cf28dfc72cac9e9f81.zip | |
Support setting thread name
Signed-off-by: Andrew Opalach <andrew@akon.city>
| -rw-r--r-- | src/common.c | 5 | ||||
| -rw-r--r-- | src/common.h | 2 | ||||
| -rw-r--r-- | src/util/thread/thread.h | 1 | ||||
| -rw-r--r-- | src/util/thread/thread_linux.c | 9 | ||||
| -rw-r--r-- | src/util/thread/thread_windows.c | 5 | ||||
| -rw-r--r-- | subprojects/libalabaster.wrap | 2 |
6 files changed, 19 insertions, 5 deletions
diff --git a/src/common.c b/src/common.c index dada6e2..1d4e3be 100644 --- a/src/common.c +++ b/src/common.c @@ -9,6 +9,7 @@ #endif #include "util/timer/timer.h" +#include "util/thread/thread.h" #include "common.h" @@ -59,8 +60,10 @@ static void malloc_unlock(void) } #endif -bool nn_common_init(void) +bool nn_common_init(const char *thread_name) { + if (thread_name) nn_thread_set_name(thread_name); + if (!setlocale(LC_ALL, "")) return false; al_set_print(al_print_default, NULL); diff --git a/src/common.h b/src/common.h index 6b02bcf..30a8464 100644 --- a/src/common.h +++ b/src/common.h @@ -2,5 +2,5 @@ #include <al/types.h> -bool nn_common_init(void); +bool nn_common_init(const char *thread_name); void nn_common_close(void); diff --git a/src/util/thread/thread.h b/src/util/thread/thread.h index 142aa3c..763fdfb 100644 --- a/src/util/thread/thread.h +++ b/src/util/thread/thread.h @@ -77,6 +77,7 @@ void nn_thread_sleep(nn_os_tstamp delay); void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userdata); void nn_thread_set_priority(s32 policy, s32 priority); +void nn_thread_set_name(const char *name); void nn_thread_join(struct nn_thread *thread); #ifdef NAUNET_HAS_THREAD_CANCEL diff --git a/src/util/thread/thread_linux.c b/src/util/thread/thread_linux.c index f5b480e..a548ff8 100644 --- a/src/util/thread/thread_linux.c +++ b/src/util/thread/thread_linux.c @@ -20,10 +20,15 @@ void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userd void nn_thread_set_priority(s32 policy, s32 priority) { - pthread_t this = pthread_self(); struct sched_param params = { 0 }; params.sched_priority = priority; - pthread_setschedparam(this, policy, ¶ms); + pthread_setschedparam(pthread_self(), policy, ¶ms); +} + +void nn_thread_set_name(const char *name) +{ + s32 ret = pthread_setname_np(pthread_self(), name); + al_assert(ret != ERANGE); } void nn_thread_join(struct nn_thread *thread) diff --git a/src/util/thread/thread_windows.c b/src/util/thread/thread_windows.c index 8722d0a..53337a4 100644 --- a/src/util/thread/thread_windows.c +++ b/src/util/thread/thread_windows.c @@ -20,6 +20,11 @@ void nn_thread_set_priority(s32 policy, s32 priority) (void)priority; } +void nn_thread_set_name(const char *name) +{ + (void)name; +} + void nn_thread_join(struct nn_thread *thread) { WaitForSingleObject(thread->thread, INFINITE); diff --git a/subprojects/libalabaster.wrap b/subprojects/libalabaster.wrap index 243dff8..81771ed 100644 --- a/subprojects/libalabaster.wrap +++ b/subprojects/libalabaster.wrap @@ -1,4 +1,4 @@ [wrap-git] url = https://git.akon.city/libalabaster -revision = ec99011aca3a9b92964c653d74d693e693ac052f +revision = b403770e7eb6e0a5a8ca14a24f91dbf214ffe917 depth = 1 |