shithub: dav1d

Download patch

ref: 15a938613d8c771ec250b1329b2df82a59eafa5f
parent: b271590aae34d3aa802d2e401b0c051ac4b4eeba
author: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date: Thu Jul 11 09:39:56 EDT 2019

Set thread names on Linux

This is using the Linux-only prctl(PR_SET_NAME, …) call, because glibc’s
pthread_setname_np() is doing exactly the same call so there is no
reason to use it instead, as it isn’t any more portable.

I don’t have any other OS to test this on, but if you want to add one
just add an #else defined(__YOUR_OS__) before the #else in thread.h.

--- a/src/thread.h
+++ b/src/thread.h
@@ -128,4 +128,20 @@
 
 #endif
 
+/* Thread naming support */
+
+#ifdef __linux__
+
+#include <sys/prctl.h>
+
+static inline void dav1d_set_thread_name(const char* name) {
+    prctl(PR_SET_NAME, name);
+}
+
+#else
+
+#define dav1d_set_thread_name(name)
+
+#endif
+
 #endif /* DAV1D_SRC_THREAD_H */
--- a/src/thread_task.c
+++ b/src/thread_task.c
@@ -32,6 +32,7 @@
 void *dav1d_frame_task(void *const data) {
     Dav1dFrameContext *const f = data;
 
+    dav1d_set_thread_name("dav1d-frame");
     pthread_mutex_lock(&f->frame_thread.td.lock);
     for (;;) {
         while (!f->n_tile_data && !f->frame_thread.die) {
@@ -61,6 +62,8 @@
     const Dav1dFrameContext *const f = t->f;
     const int tile_thread_idx = (int) (t - f->tc);
     const uint64_t mask = 1ULL << tile_thread_idx;
+
+    dav1d_set_thread_name("dav1d-tile");
 
     for (;;) {
         pthread_mutex_lock(&fttd->lock);