@@ -1976,6 +1976,7 @@ SYSTEM_FUNCS="
PeekNamedPipe
posix_memalign
pthread_cancel
+ pthread_setname_np
sched_getaffinity
SetConsoleTextAttribute
SetConsoleCtrlHandler
@@ -5765,6 +5766,7 @@ fi
if enabled pthreads; then
check_func pthread_cancel
+ check_func pthread_setname_np
fi
enabled pthreads &&
@@ -62,6 +62,8 @@ static void * attribute_align_arg worker(void *v){
ThreadContext *c = avctx->internal->frame_thread_encoder;
AVPacket *pkt = NULL;
+ avpriv_thread_setname("lavc-frame-enc");
+
while(!c->exit){
int got_packet, ret;
AVFrame *frame;
@@ -169,6 +169,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
AVCodecContext *avctx = p->avctx;
const AVCodec *codec = avctx->codec;
+ avpriv_thread_setname("lavc-frame");
+
pthread_mutex_lock(&p->mutex);
while (1) {
while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die)
@@ -70,6 +70,8 @@ static void* attribute_align_arg worker(void *v)
int thread_count = avctx->thread_count;
int self_id;
+ avpriv_thread_setname("lavc-slice");
+
pthread_mutex_lock(&c->current_job_lock);
self_id = c->current_job++;
for (;;){
@@ -61,6 +61,8 @@ static void* attribute_align_arg worker(void *v)
unsigned int last_execute = 0;
int ret, self_id;
+ avpriv_thread_setname("lavfi-worker");
+
pthread_mutex_lock(&c->current_job_lock);
self_id = c->current_job++;
@@ -181,6 +181,8 @@ static void *async_buffer_task(void *arg)
int ret = 0;
int64_t seek_ret;
+ avpriv_thread_setname("lavf-async-buf");
+
while (1) {
int fifo_space, to_copy;
@@ -36,6 +36,7 @@
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/log.h"
+#include "libavutil/thread.h"
#include "libavutil/time.h"
#include "internal.h"
#include "network.h"
@@ -502,6 +503,8 @@ static void *circular_buffer_task_rx( void *_URLContext)
UDPContext *s = h->priv_data;
int old_cancelstate;
+ avpriv_thread_setname("udp-circ-buf");
+
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate);
pthread_mutex_lock(&s->mutex);
if (ff_socket_nonblock(s->udp_fd, 0) < 0) {
@@ -29,6 +29,10 @@
#if HAVE_PTHREADS
#include <pthread.h>
+#if HAVE_PTHREAD_SETNAME_NP && defined(__linux__)
+#include <sys/prctl.h>
+#endif
+
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
#include "log.h"
@@ -127,6 +131,17 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_
#define pthread_once strict_pthread_once
#endif
+static inline void avpriv_thread_setname(const char *name)
+{
+#if HAVE_PTHREAD_SETNAME_NP
+#if defined(__APPLE__)
+ pthread_setname_np(name);
+#elif defined(__linux__)
+ prctl(PR_SET_NAME, name);
+#endif
+#endif
+}
+
#elif HAVE_OS2THREADS
#include "compat/os2threads.h"
#else
This is a re-posting of an old patch by Clément Bœsch <u@pkh.me>. Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com> --- Changes from V1: renamve function to avpriv_thread_setname use prctl on linux (universal across all libc) configure | 2 ++ libavcodec/frame_thread_encoder.c | 2 ++ libavcodec/pthread_frame.c | 2 ++ libavcodec/pthread_slice.c | 2 ++ libavfilter/pthread.c | 2 ++ libavformat/async.c | 2 ++ libavformat/udp.c | 3 +++ libavutil/thread.h | 15 +++++++++++++++ 8 files changed, 30 insertions(+)