File 0409-thread-name-setting-on-Haiku-w-32-char-names.patch of Package erlang
From cda640b6e4169490b9b89e9ee1e866dbb98711b4 Mon Sep 17 00:00:00 2001
From: Calvin Buckley <calvin@cmpct.info>
Date: Sat, 23 May 2020 16:11:00 -0300
Subject: [PATCH 09/11] thread name setting on Haiku w/ 32 char names
This uses a non-pthread API. Also double hard-coded assumptions;
on vanilla 16-char pthread systems, the set thread name function
will truncate for us.
---
erts/emulator/beam/erl_async.c | 4 ++--
erts/emulator/beam/erl_process.c | 14 +++++++-------
erts/lib_src/pthread/ethread.c | 18 +++++++++++++++++-
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/erts/emulator/beam/erl_async.c b/erts/emulator/beam/erl_async.c
index d160cda4df..536c50c283 100644
--- a/erts/emulator/beam/erl_async.c
+++ b/erts/emulator/beam/erl_async.c
@@ -155,7 +155,7 @@ erts_init_async(void)
if (erts_async_max_threads > 0) {
ErtsThrQInit_t qinit = ERTS_THR_Q_INIT_DEFAULT;
erts_thr_opts_t thr_opts = ERTS_THR_OPTS_DEFAULT_INITER;
- char *ptr, thr_name[16];
+ char *ptr, thr_name[32];
size_t tot_size = 0;
int i;
@@ -209,7 +209,7 @@ erts_init_async(void)
for (i = 0; i < erts_async_max_threads; i++) {
ErtsAsyncQ *aq = async_q(i);
- erts_snprintf(thr_opts.name, 16, "async_%d", i+1);
+ erts_snprintf(thr_opts.name, 32, "async_%d", i+1);
erts_thr_create(&aq->thr_id, async_main, (void*) aq, &thr_opts);
}
diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c
index 6c83693df8..12de96f4e9 100644
--- a/erts/emulator/beam/erl_process.c
+++ b/erts/emulator/beam/erl_process.c
@@ -8611,7 +8611,7 @@ erts_start_schedulers(void)
{
ethr_tid tid;
int res = 0;
- char name[16];
+ char name[32];
ethr_thr_opts opts = ETHR_THR_OPTS_DEFAULT_INITER;
int ix;
@@ -8621,7 +8621,7 @@ erts_start_schedulers(void)
if (erts_runq_supervision_interval) {
opts.suggested_stack_size = 16;
- erts_snprintf(opts.name, 16, "runq_supervisor");
+ erts_snprintf(opts.name, 32, "runq_supervisor");
erts_atomic_init_nob(&runq_supervisor_sleeping, 0);
if (0 != ethr_event_init(&runq_supervision_event))
erts_exit(ERTS_ABORT_EXIT, "Failed to create run-queue supervision event\n");
@@ -8642,7 +8642,7 @@ erts_start_schedulers(void)
for (ix = 0; ix < erts_no_schedulers; ix++) {
ErtsSchedulerData *esdp = ERTS_SCHEDULER_IX(ix);
ASSERT(ix == esdp->no - 1);
- erts_snprintf(opts.name, 16, "%lu_scheduler", ix + 1);
+ erts_snprintf(opts.name, 32, "%lu_scheduler", ix + 1);
res = ethr_thr_create(&esdp->tid, sched_thread_func, (void*)esdp, &opts);
if (res != 0) {
erts_exit(ERTS_ABORT_EXIT, "Failed to create scheduler thread %d, error = %d\n", ix, res);
@@ -8656,7 +8656,7 @@ erts_start_schedulers(void)
{
for (ix = 0; ix < erts_no_dirty_cpu_schedulers; ix++) {
ErtsSchedulerData *esdp = ERTS_DIRTY_CPU_SCHEDULER_IX(ix);
- erts_snprintf(opts.name, 16, "%d_dirty_cpu_scheduler", ix + 1);
+ erts_snprintf(opts.name, 32, "%d_dirty_cpu_scheduler", ix + 1);
opts.suggested_stack_size = erts_dcpu_sched_thread_suggested_stack_size;
res = ethr_thr_create(&esdp->tid,sched_dirty_cpu_thread_func,(void*)esdp,&opts);
if (res != 0)
@@ -8664,7 +8664,7 @@ erts_start_schedulers(void)
}
for (ix = 0; ix < erts_no_dirty_io_schedulers; ix++) {
ErtsSchedulerData *esdp = ERTS_DIRTY_IO_SCHEDULER_IX(ix);
- erts_snprintf(opts.name, 16, "%d_dirty_io_scheduler", ix + 1);
+ erts_snprintf(opts.name, 32, "%d_dirty_io_scheduler", ix + 1);
opts.suggested_stack_size = erts_dio_sched_thread_suggested_stack_size;
res = ethr_thr_create(&esdp->tid,sched_dirty_io_thread_func,(void*)esdp,&opts);
if (res != 0)
@@ -8672,7 +8672,7 @@ erts_start_schedulers(void)
}
}
- erts_snprintf(opts.name, 16, "aux");
+ erts_snprintf(opts.name, 32, "aux");
res = ethr_thr_create(&tid, aux_thread, NULL, &opts);
if (res != 0)
@@ -8694,7 +8694,7 @@ erts_start_schedulers(void)
bpt->blocked = 0;
bpt->id = ix;
- erts_snprintf(opts.name, 16, "%d_poller", ix);
+ erts_snprintf(opts.name, 32, "%d_poller", ix);
res = ethr_thr_create(&tid, poll_thread, (void*) bpt, &opts);
if (res != 0)
diff --git a/erts/lib_src/pthread/ethread.c b/erts/lib_src/pthread/ethread.c
index dbf1b56683..9dcc2c505d 100644
--- a/erts/lib_src/pthread/ethread.c
+++ b/erts/lib_src/pthread/ethread.c
@@ -47,6 +47,10 @@
#include <limits.h>
+#if defined (__HAIKU__)
+#include <os/kernel/OS.h>
+#endif
+
#define ETHR_INLINE_FUNC_NAME_(X) X ## __
#define ETHREAD_IMPL__
@@ -83,7 +87,7 @@ typedef struct {
void *prep_func_res;
size_t stacksize;
char *name;
- char name_buff[16];
+ char name_buff[32];
} ethr_thr_wrap_data__;
static void *thr_wrapper(void *vtwd)
@@ -337,7 +341,11 @@ ethr_thr_create(ethr_tid *tid, void * (*func)(void *), void *arg,
twd.stacksize = 0;
if (opts && opts->name) {
+#ifdef __HAIKU__
+ snprintf(twd.name_buff, B_OS_NAME_LENGTH, "%s", opts->name);
+#else
snprintf(twd.name_buff, 16, "%s", opts->name);
+#endif
twd.name = twd.name_buff;
} else
twd.name = NULL;
@@ -498,6 +506,14 @@ ethr_setname(char *name)
pthread_set_name_np(ethr_self(), name);
#elif defined(ETHR_HAVE_PTHREAD_SETNAME_NP_1)
pthread_setname_np(name);
+#elif defined(__HAIKU__)
+ thread_id haiku_tid;
+ haiku_tid = get_pthread_thread_id(ethr_self());
+ if (!name) {
+ rename_thread (haiku_tid, "");
+ } else {
+ rename_thread (haiku_tid, name);
+ }
#endif
}
--
2.26.2