Skip to content

Commit 578e2ef

Browse files
committed
setThreadName()
1 parent 8f160e7 commit 578e2ef

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ReadoutUtils.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,20 @@ int numaGetNodeFromAddress(void *ptr, int &node) {
298298
#endif
299299
return -1;
300300
}
301+
302+
// function to set a name for current thread
303+
void setThreadName(const char* name) {
304+
#ifdef _GNU_SOURCE
305+
char buf[16] = "readout";
306+
if (name != nullptr) {
307+
strncpy(buf, name, sizeof(buf)-1);
308+
buf[sizeof(buf)-1] = 0;
309+
}
310+
pthread_setname_np(pthread_self(), buf);
311+
// ortherwise
312+
// prctl(PR_SET_NAME, ...)
313+
#else
314+
// prevent warning for unused parameter
315+
(void)name;
316+
#endif
317+
}

src/ReadoutUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ int numaBind(int numaNode);
8080
// returns 0 on success, or an error code
8181
int numaGetNodeFromAddress(void *ptr, int &node);
8282

83+
// function to set a name for current thread
84+
void setThreadName(const char*name);
85+
8386
// end of _READOUTUTILS_H
8487
#endif
8588

0 commit comments

Comments
 (0)