summaryrefslogtreecommitdiff
path: root/lib/frr_pthread.c
diff options
context:
space:
mode:
authorChirag Shah <chirag@cumulusnetworks.com>2018-07-30 08:05:42 -0700
committerChirag Shah <chirag@cumulusnetworks.com>2018-08-29 15:41:54 -0700
commit57019528a0279c3a6b2caa2100f5c6199ad378f2 (patch)
treef36321071410a60a4df64d33bd19039421408f09 /lib/frr_pthread.c
parent2e7d2b93b6a6ecbc97f7e1e722c847a7f471afde (diff)
*: pthread set name abstraction
Testing Done: TOR#cat /proc/2670/task/2672/comm bgpd_ka TOR# ps H -C bgpd -o 'pid tid cmd comm' PID TID CMD COMMAND 2670 2670 /usr/lib/frr/bgpd -M snmp - bgpd 2670 2671 /usr/lib/frr/bgpd -M snmp - bgpd 2670 2672 /usr/lib/frr/bgpd -M snmp - bgpd_ka Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
Diffstat (limited to 'lib/frr_pthread.c')
-rw-r--r--lib/frr_pthread.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index f5a6383f48..eb6587a35a 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -85,7 +85,7 @@ void frr_pthread_finish()
}
struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
- const char *name)
+ const char *name, const char *os_name)
{
static struct frr_pthread holder = {};
struct frr_pthread *fpt = NULL;
@@ -107,6 +107,9 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
fpt->attr = *attr;
name = (name ? name : "Anonymous thread");
fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ if (os_name)
+ snprintf(fpt->os_name, OS_THREAD_NAMELEN,
+ "%s", os_name);
if (attr == &frr_pthread_attr_default)
fpt->attr.id = frr_pthread_get_id();
/* initialize startup synchronization primitives */
@@ -140,16 +143,34 @@ void frr_pthread_destroy(struct frr_pthread *fpt)
XFREE(MTYPE_FRR_PTHREAD, fpt);
}
-void frr_pthread_set_name(struct frr_pthread *fpt, const char *name)
+int frr_pthread_set_name(struct frr_pthread *fpt, const char *name,
+ const char *os_name)
{
- pthread_mutex_lock(&fpt->mtx);
- {
- if (fpt->name)
- XFREE(MTYPE_FRR_PTHREAD, fpt->name);
- fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ int ret = 0;
+
+ if (name) {
+ pthread_mutex_lock(&fpt->mtx);
+ {
+ if (fpt->name)
+ XFREE(MTYPE_FRR_PTHREAD, fpt->name);
+ fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name);
+ }
+ pthread_mutex_unlock(&fpt->mtx);
+ thread_master_set_name(fpt->master, name);
}
- pthread_mutex_unlock(&fpt->mtx);
- thread_master_set_name(fpt->master, name);
+
+ if (os_name) {
+ pthread_mutex_lock(&fpt->mtx);
+ snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name);
+ pthread_mutex_unlock(&fpt->mtx);
+#ifdef GNU_LINUX
+ ret = pthread_setname_np(fpt->thread, fpt->os_name);
+#elif defined(OPEN_BSD)
+ ret = pthread_set_name_np(fpt->thread, fpt->os_name);
+#endif
+ }
+
+ return ret;
}
struct frr_pthread *frr_pthread_get(uint32_t id)
@@ -311,6 +332,9 @@ static void *fpt_run(void *arg)
fpt->master->handle_signals = false;
+ if (fpt->os_name)
+ frr_pthread_set_name(fpt, NULL, fpt->os_name);
+
frr_pthread_notify_running(fpt);
struct thread task;