On Wed, Jan 20, 2016 at 07:29:02PM -0300, James Almer wrote:
[...]
> CC      libavformat/async.o
> F:/msys/ffmpeg/src/libavformat/async.c: In function 'async_buffer_task':
> F:/msys/ffmpeg/src/libavformat/async.c:184:5: error: implicit declaration of 
> function 'ff_thread_setname' [-Werror=implicit-function-declaration]
>      ff_thread_setname("lavf-async-buf");
>      ^
> cc1.exe: some warnings being treated as errors
> /ffmpeg/src/common.mak:60: recipe for target 'libavformat/async.o' failed
> make: *** [libavformat/async.o] Error 1
> 
> You forgot w32threads and os2threads :P
> 

derp, added a define locally in this scope as well, thanks. New patch
attached.

> Quickest fix is to also define ff_thread_setname to (0) for those, like you're
> doing for the no threads builds.

> Proper fix IMO would be to do what i mentioned in my other reply to leave 
> things
> ready in case someone wants to implement this function at a latter time.
> 

I don't really like the idea of writing a pthread_setname() function (if
this function becomes standard one day it's going to be named as such and
will break things)

[...]

-- 
Clément B.
From 1b2ac3cd800356a9fbde2cb45415b92ce776fb91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <u...@pkh.me>
Date: Wed, 20 Jan 2016 21:30:32 +0100
Subject: [PATCH] lavu: add ff_pthread_setname() and use it in various places

---
 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                | 12 ++++++++++++
 7 files changed, 25 insertions(+)

diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index f4d35f9..87570a4 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -62,6 +62,8 @@ static void * attribute_align_arg worker(void *v){
     ThreadContext *c = avctx->internal->frame_thread_encoder;
     AVPacket *pkt = NULL;
 
+    ff_thread_setname("lavc-frame-enc");
+
     while(!c->exit){
         int got_packet, ret;
         AVFrame *frame;
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index b77dd1e..6374d7c 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -132,6 +132,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
     AVCodecContext *avctx = p->avctx;
     const AVCodec *codec = avctx->codec;
 
+    ff_thread_setname("lavc-frame");
+
     pthread_mutex_lock(&p->mutex);
     while (1) {
             while (p->state == STATE_INPUT_READY && !fctx->die)
diff --git a/libavcodec/pthread_slice.c b/libavcodec/pthread_slice.c
index 3ba5c66..25658e6 100644
--- a/libavcodec/pthread_slice.c
+++ b/libavcodec/pthread_slice.c
@@ -70,6 +70,8 @@ static void* attribute_align_arg worker(void *v)
     int thread_count = avctx->thread_count;
     int self_id;
 
+    ff_thread_setname("lavc-slice");
+
     pthread_mutex_lock(&c->current_job_lock);
     self_id = c->current_job++;
     for (;;){
diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c
index 1c54193..53d4c74 100644
--- a/libavfilter/pthread.c
+++ b/libavfilter/pthread.c
@@ -63,6 +63,8 @@ static void* attribute_align_arg worker(void *v)
     unsigned int last_execute = 0;
     int self_id;
 
+    ff_thread_setname("lavfi-worker");
+
     pthread_mutex_lock(&c->current_job_lock);
     self_id = c->current_job++;
     for (;;) {
diff --git a/libavformat/async.c b/libavformat/async.c
index 4308c4b..9f4d553 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -181,6 +181,8 @@ static void *async_buffer_task(void *arg)
     int           ret  = 0;
     int64_t       seek_ret;
 
+    ff_thread_setname("lavf-async-buf");
+
     while (1) {
         int fifo_space, to_copy;
 
diff --git a/libavformat/udp.c b/libavformat/udp.c
index ea80e52..e053a91 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -35,6 +35,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"
@@ -492,6 +493,8 @@ static void *circular_buffer_task( void *_URLContext)
     UDPContext *s = h->priv_data;
     int old_cancelstate;
 
+    ff_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) {
diff --git a/libavutil/thread.h b/libavutil/thread.h
index 32ddf40..42430fb 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -31,6 +31,15 @@
 #if HAVE_PTHREADS
 #include <pthread.h>
 
+static inline void ff_thread_setname(const char *name)
+{
+#if defined(__APPLE__)
+    pthread_setname_np(name);
+#elif defined(__linux__) && defined(__GLIBC__)
+    pthread_setname_np(pthread_self(), name);
+#endif
+}
+
 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
 
 #include "log.h"
@@ -143,6 +152,7 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_
 #define AV_ONCE_INIT PTHREAD_ONCE_INIT
 
 #define ff_thread_once(control, routine) pthread_once(control, routine)
+#define ff_thread_setname(name) (0)
 
 #else
 
@@ -158,6 +168,8 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_
 #define AVOnce char
 #define AV_ONCE_INIT 0
 
+#define ff_thread_setname(name) (0)
+
 static inline int ff_thread_once(char *control, void (*routine)(void))
 {
     if (!*control) {
-- 
2.7.0

Attachment: signature.asc
Description: PGP signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to