On Sun, Jan 24, 2016 at 07:00:30PM -0300, James Almer wrote: > On 1/24/2016 6:22 PM, Clément Bœsch wrote: > > On Sun, Jan 24, 2016 at 10:09:49PM +0100, Michael Niedermayer wrote: > > [...] > >> fails to build: > >> make distclean ; ../configure --enable-pthreads --arch=x86_32 > >> --target-os=linux --extra-cflags=-m32 --extra-ldflags=-m32 > >> --enable-cross-compile && make -j12 > >> In file included from libavfilter/pthread.c:30:0: > >> ffmpeg/libavutil/thread.h: In function ‘ff_thread_setname’: > >> ffmpeg/libavutil/thread.h:134:5: error: implicit declaration of function > >> ‘pthread_setname_np’ [-Werror=implicit-function-declaration] > >> > > > > Any idea what could be the cause? Old glibc maybe? > > In any case, i guess the only solution would be to do a configure check > like the one for pthread_cancel, or a more complete one that checks the > actual signature of the function.
I added an extra simple check in the attached patch. I wasn't able to make a more complete check (i was able to compile, link, and even execute pthread_setname_np("ffmpeg") on linux). -- Clément B.
From 1dca0b8202882e84db0d31023577a67dfc5d5d83 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_thread_setname() and use it in various places --- 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(+) diff --git a/configure b/configure index dba8180..a51a5e9 100755 --- a/configure +++ b/configure @@ -1877,6 +1877,7 @@ SYSTEM_FUNCS=" PeekNamedPipe posix_memalign pthread_cancel + pthread_setname_np sched_getaffinity SetConsoleTextAttribute SetConsoleCtrlHandler @@ -5418,6 +5419,7 @@ fi if enabled pthreads; then check_func pthread_cancel + check_func pthread_setname_np fi disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 04c9a0e..aaf3166 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 96a7643..fbb4a53 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 37ca73f..a53ae9c 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..13bdf57 100644 --- a/libavutil/thread.h +++ b/libavutil/thread.h @@ -126,10 +126,23 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #define pthread_once strict_pthread_once #endif +static inline void ff_thread_setname(const char *name) +{ +#if HAVE_PTHREAD_SETNAME_NP +#if defined(__APPLE__) + pthread_setname_np(name); +#elif defined(__linux__) && defined(__GLIBC__) + pthread_setname_np(pthread_self(), name); +#endif +#endif +} + #elif HAVE_OS2THREADS #include "compat/os2threads.h" +#define ff_thread_setname(name) (0) #else #include "compat/w32pthreads.h" +#define ff_thread_setname(name) (0) #endif #define AVMutex pthread_mutex_t @@ -158,6 +171,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
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel