aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2020-08-08 18:25:48 -0700
committerGarrett D'Amore <garrett@damore.org>2020-08-08 19:30:17 -0700
commit6c5070d9157ab0de667568655f0bbeb60780d701 (patch)
treeab1a03e16907c97e6d76f1d95d79aea0f4a875ce /src/core
parentddc0d044dd0fcf4aa1dc333fd5bda0de47850a64 (diff)
downloadnng-6c5070d9157ab0de667568655f0bbeb60780d701.tar.gz
nng-6c5070d9157ab0de667568655f0bbeb60780d701.tar.bz2
nng-6c5070d9157ab0de667568655f0bbeb60780d701.zip
fixes #960 NNG threads inherit application thread name
This also exposes an nng_thread_set_name() function for applications to use. All NNG thread names start with "nng:". Note that support is highly dependent on the operating system.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/aio.c2
-rw-r--r--src/core/platform.h4
-rw-r--r--src/core/reap.c6
-rw-r--r--src/core/taskq.c4
-rw-r--r--src/core/thread.c8
-rw-r--r--src/core/thread.h5
-rw-r--r--src/core/timer.c4
7 files changed, 27 insertions, 6 deletions
diff --git a/src/core/aio.c b/src/core/aio.c
index ea2203f2..97bb9153 100644
--- a/src/core/aio.c
+++ b/src/core/aio.c
@@ -488,6 +488,8 @@ nni_aio_expire_loop(void *unused)
NNI_ARG_UNUSED(unused);
+ nni_thr_set_name(NULL, "nng:aio:expire");
+
for (;;) {
nni_aio_cancelfn fn;
nni_time now;
diff --git a/src/core/platform.h b/src/core/platform.h
index c6f4ef30..6eff2f7d 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -157,6 +157,10 @@ extern void nni_plat_thr_fini(nni_plat_thr *);
// prevention in callbacks, for example.)
extern bool nni_plat_thr_is_self(nni_plat_thr *);
+// nni_plat_thr_set_name is used to set the thread name, which
+// should be a short ASCII string. It may or may not be supported --
+// this is intended to facilitate debugging.
+extern void nni_plat_thr_set_name(nni_plat_thr *, const char *);
//
// Atomics support. This will evolve over time.
//
diff --git a/src/core/reap.c b/src/core/reap.c
index bfad6c32..ddd2a06e 100644
--- a/src/core/reap.c
+++ b/src/core/reap.c
@@ -1,5 +1,5 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -27,7 +27,9 @@ reap_worker(void *notused)
{
NNI_ARG_UNUSED(notused);
- nni_mtx_lock(&reap_mtx);
+ nni_thr_set_name(NULL, "nng:reap");
+
+ nni_mtx_lock(&reap_mtx);
for (;;) {
nni_reap_item *item;
while ((item = nni_list_first(&reap_list)) != NULL) {
diff --git a/src/core/taskq.c b/src/core/taskq.c
index fbd93ebe..9ccd5845 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -34,7 +34,9 @@ nni_taskq_thread(void *self)
nni_taskq * tq = thr->tqt_tq;
nni_task * task;
- nni_mtx_lock(&tq->tq_mtx);
+ nni_thr_set_name(NULL, "nng:task");
+
+ nni_mtx_lock(&tq->tq_mtx);
for (;;) {
if ((task = nni_list_first(&tq->tq_tasks)) != NULL) {
diff --git a/src/core/thread.c b/src/core/thread.c
index adc35542..986ff331 100644
--- a/src/core/thread.c
+++ b/src/core/thread.c
@@ -1,5 +1,5 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -182,3 +182,9 @@ nni_thr_is_self(nni_thr *thr)
}
return (nni_plat_thr_is_self(&thr->thr));
}
+
+void
+nni_thr_set_name(nni_thr *thr, const char *name)
+{
+ nni_plat_thr_set_name(&thr->thr, name);
+} \ No newline at end of file
diff --git a/src/core/thread.h b/src/core/thread.h
index c3d5531e..154b4616 100644
--- a/src/core/thread.h
+++ b/src/core/thread.h
@@ -1,5 +1,5 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -85,4 +85,7 @@ extern void nni_thr_wait(nni_thr *thr);
// nni_thr_is_self returns true if the caller is the named thread.
extern bool nni_thr_is_self(nni_thr *thr);
+// nni_thr_set_name is used to set a short name for the thread.
+extern void nni_thr_set_name(nni_thr *thr, const char *);
+
#endif // CORE_THREAD_H
diff --git a/src/core/timer.c b/src/core/timer.c
index ad47ae33..36024817 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -136,6 +136,8 @@ nni_timer_loop(void *arg)
nni_time now;
nni_timer_node *node;
+ nni_thr_set_name(NULL, "nng:timer");
+
for (;;) {
nni_mtx_lock(&timer->t_mx);
timer->t_active = NULL;