diff mbox series

[FFmpeg-devel,v2] lavu/thread: add support for setting thread name on *bsd and solaris

Message ID ZZo8511zgYcXMWha@humpty.home.comstyle.com
State Accepted
Commit fd16d8c68cd7b820eda76c407b0645b7cf470efd
Headers show
Series [FFmpeg-devel,v2] lavu/thread: add support for setting thread name on *bsd and solaris | expand

Checks

Context Check Description
yinshiyou/make_fate_loongarch64 success Make fate finished
yinshiyou/make_loongarch64 warning New warnings during build
andriy/make_fate_x86 success Make fate finished
andriy/make_x86 warning New warnings during build

Commit Message

Brad Smith Jan. 7, 2024, 5:55 a.m. UTC
lavu/thread: add support for setting thread name on *bsd and solaris

FreeBSD/DragonFly/Solaris use pthread_setname_np(). OpenBSD uses pthread_set_name_np().

Signed-off-by: Brad Smith <brad@comstyle.com>
---
 configure          | 10 ++++++++++
 libavutil/thread.h | 14 ++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

Comments

Brad Smith Jan. 16, 2024, 6:25 a.m. UTC | #1
On 2024-01-07 12:55 a.m., Brad Smith wrote:
> lavu/thread: add support for setting thread name on *bsd and solaris
>
> FreeBSD/DragonFly/Solaris use pthread_setname_np(). OpenBSD uses pthread_set_name_np().
>
> Signed-off-by: Brad Smith<brad@comstyle.com>
> ---
>   configure          | 10 ++++++++++
>   libavutil/thread.h | 14 ++++++++++++--
>   2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 0b5e83bd20..67660b6292 100755
> --- a/configure
> +++ b/configure
> @@ -2239,6 +2239,7 @@ HEADERS_LIST="
>       opencv2_core_core_c_h
>       OpenGL_gl3_h
>       poll_h
> +    pthread_np_h
>       sys_param_h
>       sys_resource_h
>       sys_select_h
> @@ -2341,6 +2342,8 @@ SYSTEM_FUNCS="
>       posix_memalign
>       prctl
>       pthread_cancel
> +    pthread_set_name_np
> +    pthread_setname_np
>       sched_getaffinity
>       SecItemImport
>       SetConsoleTextAttribute
> @@ -6523,6 +6526,7 @@ check_headers malloc.h
>   check_headers mftransform.h
>   check_headers net/udplite.h
>   check_headers poll.h
> +check_headers pthread_np.h
>   check_headers sys/param.h
>   check_headers sys/resource.h
>   check_headers sys/select.h
> @@ -6691,6 +6695,12 @@ if ! disabled pthreads && ! enabled w32threads && ! enabled os2threads; then
>       if enabled pthreads; then
>           check_builtin sem_timedwait semaphore.h "sem_t *s; sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" $pthreads_extralibs
>           check_func pthread_cancel $pthreads_extralibs
> +        hdrs=pthread.h
> +        if enabled pthread_np_h; then
> +            hdrs="$hdrs pthread_np.h"
> +        fi
> +        check_lib pthread_set_name_np "$hdrs" pthread_set_name_np -lpthread
> +        check_lib pthread_setname_np "$hdrs" pthread_setname_np -lpthread
>       fi
>   fi
>   
> diff --git a/libavutil/thread.h b/libavutil/thread.h
> index 2ded498c89..fa74dd2ea7 100644
> --- a/libavutil/thread.h
> +++ b/libavutil/thread.h
> @@ -26,6 +26,8 @@
>   
>   #if HAVE_PRCTL
>   #include <sys/prctl.h>
> +#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
> +#include <pthread_np.h>
>   #endif
>   
>   #include "error.h"
> @@ -213,11 +215,19 @@ static inline int ff_thread_once(char *control, void (*routine)(void))
>   
>   static inline int ff_thread_setname(const char *name)
>   {
> +    int ret = 0;
> +
>   #if HAVE_PRCTL
> -    return AVERROR(prctl(PR_SET_NAME, name));
> +    ret = AVERROR(prctl(PR_SET_NAME, name));
> +#elif HAVE_PTHREAD_SETNAME_NP
> +    ret = AVERROR(pthread_setname_np(pthread_self(), name));
> +#elif HAVE_PTHREAD_SET_NAME_NP
> +    pthread_set_name_np(pthread_self(), name);
> +#else
> +    ret = AVERROR(ENOSYS);
>   #endif
>   
> -    return AVERROR(ENOSYS);
> +    return ret;
>   }
>   
>   #endif /* AVUTIL_THREAD_H */


ping.
Brad Smith Jan. 23, 2024, 7:44 p.m. UTC | #2
On 2024-01-16 1:25 a.m., Brad Smith wrote:
> On 2024-01-07 12:55 a.m., Brad Smith wrote:
>> lavu/thread: add support for setting thread name on *bsd and solaris
>>
>> FreeBSD/DragonFly/Solaris use pthread_setname_np(). OpenBSD uses 
>> pthread_set_name_np().
>>
>> Signed-off-by: Brad Smith<brad@comstyle.com>
>> ---
>>   configure          | 10 ++++++++++
>>   libavutil/thread.h | 14 ++++++++++++--
>>   2 files changed, 22 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 0b5e83bd20..67660b6292 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2239,6 +2239,7 @@ HEADERS_LIST="
>>       opencv2_core_core_c_h
>>       OpenGL_gl3_h
>>       poll_h
>> +    pthread_np_h
>>       sys_param_h
>>       sys_resource_h
>>       sys_select_h
>> @@ -2341,6 +2342,8 @@ SYSTEM_FUNCS="
>>       posix_memalign
>>       prctl
>>       pthread_cancel
>> +    pthread_set_name_np
>> +    pthread_setname_np
>>       sched_getaffinity
>>       SecItemImport
>>       SetConsoleTextAttribute
>> @@ -6523,6 +6526,7 @@ check_headers malloc.h
>>   check_headers mftransform.h
>>   check_headers net/udplite.h
>>   check_headers poll.h
>> +check_headers pthread_np.h
>>   check_headers sys/param.h
>>   check_headers sys/resource.h
>>   check_headers sys/select.h
>> @@ -6691,6 +6695,12 @@ if ! disabled pthreads && ! enabled w32threads 
>> && ! enabled os2threads; then
>>       if enabled pthreads; then
>>           check_builtin sem_timedwait semaphore.h "sem_t *s; 
>> sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" $pthreads_extralibs
>>           check_func pthread_cancel $pthreads_extralibs
>> +        hdrs=pthread.h
>> +        if enabled pthread_np_h; then
>> +            hdrs="$hdrs pthread_np.h"
>> +        fi
>> +        check_lib pthread_set_name_np "$hdrs" pthread_set_name_np 
>> -lpthread
>> +        check_lib pthread_setname_np "$hdrs" pthread_setname_np 
>> -lpthread
>>       fi
>>   fi
>>   diff --git a/libavutil/thread.h b/libavutil/thread.h
>> index 2ded498c89..fa74dd2ea7 100644
>> --- a/libavutil/thread.h
>> +++ b/libavutil/thread.h
>> @@ -26,6 +26,8 @@
>>     #if HAVE_PRCTL
>>   #include <sys/prctl.h>
>> +#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && 
>> HAVE_PTHREAD_NP_H
>> +#include <pthread_np.h>
>>   #endif
>>     #include "error.h"
>> @@ -213,11 +215,19 @@ static inline int ff_thread_once(char *control, 
>> void (*routine)(void))
>>     static inline int ff_thread_setname(const char *name)
>>   {
>> +    int ret = 0;
>> +
>>   #if HAVE_PRCTL
>> -    return AVERROR(prctl(PR_SET_NAME, name));
>> +    ret = AVERROR(prctl(PR_SET_NAME, name));
>> +#elif HAVE_PTHREAD_SETNAME_NP
>> +    ret = AVERROR(pthread_setname_np(pthread_self(), name));
>> +#elif HAVE_PTHREAD_SET_NAME_NP
>> +    pthread_set_name_np(pthread_self(), name);
>> +#else
>> +    ret = AVERROR(ENOSYS);
>>   #endif
>>   -    return AVERROR(ENOSYS);
>> +    return ret;
>>   }
>>     #endif /* AVUTIL_THREAD_H */
>
>
> ping.

ping.
Brad Smith Jan. 31, 2024, 6:54 a.m. UTC | #3
On 2024-01-23 2:44 p.m., Brad Smith wrote:
> On 2024-01-16 1:25 a.m., Brad Smith wrote:
>> On 2024-01-07 12:55 a.m., Brad Smith wrote:
>>> lavu/thread: add support for setting thread name on *bsd and solaris
>>>
>>> FreeBSD/DragonFly/Solaris use pthread_setname_np(). OpenBSD uses 
>>> pthread_set_name_np().
>>>
>>> Signed-off-by: Brad Smith<brad@comstyle.com>
>>> ---
>>>   configure          | 10 ++++++++++
>>>   libavutil/thread.h | 14 ++++++++++++--
>>>   2 files changed, 22 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/configure b/configure
>>> index 0b5e83bd20..67660b6292 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -2239,6 +2239,7 @@ HEADERS_LIST="
>>>       opencv2_core_core_c_h
>>>       OpenGL_gl3_h
>>>       poll_h
>>> +    pthread_np_h
>>>       sys_param_h
>>>       sys_resource_h
>>>       sys_select_h
>>> @@ -2341,6 +2342,8 @@ SYSTEM_FUNCS="
>>>       posix_memalign
>>>       prctl
>>>       pthread_cancel
>>> +    pthread_set_name_np
>>> +    pthread_setname_np
>>>       sched_getaffinity
>>>       SecItemImport
>>>       SetConsoleTextAttribute
>>> @@ -6523,6 +6526,7 @@ check_headers malloc.h
>>>   check_headers mftransform.h
>>>   check_headers net/udplite.h
>>>   check_headers poll.h
>>> +check_headers pthread_np.h
>>>   check_headers sys/param.h
>>>   check_headers sys/resource.h
>>>   check_headers sys/select.h
>>> @@ -6691,6 +6695,12 @@ if ! disabled pthreads && ! enabled 
>>> w32threads && ! enabled os2threads; then
>>>       if enabled pthreads; then
>>>           check_builtin sem_timedwait semaphore.h "sem_t *s; 
>>> sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" 
>>> $pthreads_extralibs
>>>           check_func pthread_cancel $pthreads_extralibs
>>> +        hdrs=pthread.h
>>> +        if enabled pthread_np_h; then
>>> +            hdrs="$hdrs pthread_np.h"
>>> +        fi
>>> +        check_lib pthread_set_name_np "$hdrs" pthread_set_name_np 
>>> -lpthread
>>> +        check_lib pthread_setname_np "$hdrs" pthread_setname_np 
>>> -lpthread
>>>       fi
>>>   fi
>>>   diff --git a/libavutil/thread.h b/libavutil/thread.h
>>> index 2ded498c89..fa74dd2ea7 100644
>>> --- a/libavutil/thread.h
>>> +++ b/libavutil/thread.h
>>> @@ -26,6 +26,8 @@
>>>     #if HAVE_PRCTL
>>>   #include <sys/prctl.h>
>>> +#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && 
>>> HAVE_PTHREAD_NP_H
>>> +#include <pthread_np.h>
>>>   #endif
>>>     #include "error.h"
>>> @@ -213,11 +215,19 @@ static inline int ff_thread_once(char 
>>> *control, void (*routine)(void))
>>>     static inline int ff_thread_setname(const char *name)
>>>   {
>>> +    int ret = 0;
>>> +
>>>   #if HAVE_PRCTL
>>> -    return AVERROR(prctl(PR_SET_NAME, name));
>>> +    ret = AVERROR(prctl(PR_SET_NAME, name));
>>> +#elif HAVE_PTHREAD_SETNAME_NP
>>> +    ret = AVERROR(pthread_setname_np(pthread_self(), name));
>>> +#elif HAVE_PTHREAD_SET_NAME_NP
>>> +    pthread_set_name_np(pthread_self(), name);
>>> +#else
>>> +    ret = AVERROR(ENOSYS);
>>>   #endif
>>>   -    return AVERROR(ENOSYS);
>>> +    return ret;
>>>   }
>>>     #endif /* AVUTIL_THREAD_H */
>>
>>
>> ping.
>
> ping.


ping.
Marton Balint Feb. 4, 2024, 7:41 p.m. UTC | #4
On Wed, 31 Jan 2024, Brad Smith wrote:

> On 2024-01-23 2:44 p.m., Brad Smith wrote:
>>  On 2024-01-16 1:25 a.m., Brad Smith wrote:
>>>  On 2024-01-07 12:55 a.m., Brad Smith wrote:
>>>>  lavu/thread: add support for setting thread name on *bsd and solaris
>>>>
>>>>  FreeBSD/DragonFly/Solaris use pthread_setname_np(). OpenBSD uses
>>>>  pthread_set_name_np().
>>>>
>>>>  Signed-off-by: Brad Smith<brad@comstyle.com>
>>>>  ---
>>>>    configure          | 10 ++++++++++
>>>>    libavutil/thread.h | 14 ++++++++++++--
>>>>    2 files changed, 22 insertions(+), 2 deletions(-)
>>>>
>>>>  diff --git a/configure b/configure
>>>>  index 0b5e83bd20..67660b6292 100755
>>>>  --- a/configure
>>>>  +++ b/configure
>>>>  @@ -2239,6 +2239,7 @@ HEADERS_LIST="
>>>>        opencv2_core_core_c_h
>>>>        OpenGL_gl3_h
>>>>        poll_h
>>>>  +    pthread_np_h
>>>>        sys_param_h
>>>>        sys_resource_h
>>>>        sys_select_h
>>>>  @@ -2341,6 +2342,8 @@ SYSTEM_FUNCS="
>>>>        posix_memalign
>>>>        prctl
>>>>        pthread_cancel
>>>>  +    pthread_set_name_np
>>>>  +    pthread_setname_np
>>>>        sched_getaffinity
>>>>        SecItemImport
>>>>        SetConsoleTextAttribute
>>>>  @@ -6523,6 +6526,7 @@ check_headers malloc.h
>>>>    check_headers mftransform.h
>>>>    check_headers net/udplite.h
>>>>    check_headers poll.h
>>>>  +check_headers pthread_np.h
>>>>    check_headers sys/param.h
>>>>    check_headers sys/resource.h
>>>>    check_headers sys/select.h
>>>>  @@ -6691,6 +6695,12 @@ if ! disabled pthreads && ! enabled w32threads &&
>>>>  ! enabled os2threads; then
>>>>        if enabled pthreads; then
>>>>            check_builtin sem_timedwait semaphore.h "sem_t *s;
>>>>  sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" $pthreads_extralibs
>>>>            check_func pthread_cancel $pthreads_extralibs
>>>>  +        hdrs=pthread.h
>>>>  +        if enabled pthread_np_h; then
>>>>  +            hdrs="$hdrs pthread_np.h"
>>>>  +        fi
>>>>  +        check_lib pthread_set_name_np "$hdrs" pthread_set_name_np
>>>>  -lpthread
>>>>  +        check_lib pthread_setname_np "$hdrs" pthread_setname_np
>>>>  -lpthread
>>>>        fi
>>>>    fi
>>>>    diff --git a/libavutil/thread.h b/libavutil/thread.h
>>>>  index 2ded498c89..fa74dd2ea7 100644
>>>>  --- a/libavutil/thread.h
>>>>  +++ b/libavutil/thread.h
>>>>  @@ -26,6 +26,8 @@
>>>>      #if HAVE_PRCTL
>>>>    #include <sys/prctl.h>
>>>>  +#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) &&
>>>>  HAVE_PTHREAD_NP_H
>>>>  +#include <pthread_np.h>
>>>>    #endif
>>>>      #include "error.h"
>>>>  @@ -213,11 +215,19 @@ static inline int ff_thread_once(char *control,
>>>>  void (*routine)(void))
>>>>      static inline int ff_thread_setname(const char *name)
>>>>    {
>>>>  +    int ret = 0;
>>>>  +
>>>>    #if HAVE_PRCTL
>>>>  -    return AVERROR(prctl(PR_SET_NAME, name));
>>>>  +    ret = AVERROR(prctl(PR_SET_NAME, name));
>>>>  +#elif HAVE_PTHREAD_SETNAME_NP
>>>>  +    ret = AVERROR(pthread_setname_np(pthread_self(), name));
>>>>  +#elif HAVE_PTHREAD_SET_NAME_NP
>>>>  +    pthread_set_name_np(pthread_self(), name);
>>>>  +#else
>>>>  +    ret = AVERROR(ENOSYS);
>>>>    #endif
>>>>    -    return AVERROR(ENOSYS);
>>>>  +    return ret;
>>>>    }
>>>>      #endif /* AVUTIL_THREAD_H */
>>> 
>>>
>>>  ping.
>>
>>  ping.
>
>
> ping.

Will apply.

Thanks,
Marton
diff mbox series

Patch

diff --git a/configure b/configure
index 0b5e83bd20..67660b6292 100755
--- a/configure
+++ b/configure
@@ -2239,6 +2239,7 @@  HEADERS_LIST="
     opencv2_core_core_c_h
     OpenGL_gl3_h
     poll_h
+    pthread_np_h
     sys_param_h
     sys_resource_h
     sys_select_h
@@ -2341,6 +2342,8 @@  SYSTEM_FUNCS="
     posix_memalign
     prctl
     pthread_cancel
+    pthread_set_name_np
+    pthread_setname_np
     sched_getaffinity
     SecItemImport
     SetConsoleTextAttribute
@@ -6523,6 +6526,7 @@  check_headers malloc.h
 check_headers mftransform.h
 check_headers net/udplite.h
 check_headers poll.h
+check_headers pthread_np.h
 check_headers sys/param.h
 check_headers sys/resource.h
 check_headers sys/select.h
@@ -6691,6 +6695,12 @@  if ! disabled pthreads && ! enabled w32threads && ! enabled os2threads; then
     if enabled pthreads; then
         check_builtin sem_timedwait semaphore.h "sem_t *s; sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" $pthreads_extralibs
         check_func pthread_cancel $pthreads_extralibs
+        hdrs=pthread.h
+        if enabled pthread_np_h; then
+            hdrs="$hdrs pthread_np.h"
+        fi
+        check_lib pthread_set_name_np "$hdrs" pthread_set_name_np -lpthread
+        check_lib pthread_setname_np "$hdrs" pthread_setname_np -lpthread
     fi
 fi
 
diff --git a/libavutil/thread.h b/libavutil/thread.h
index 2ded498c89..fa74dd2ea7 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -26,6 +26,8 @@ 
 
 #if HAVE_PRCTL
 #include <sys/prctl.h>
+#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
 #endif
 
 #include "error.h"
@@ -213,11 +215,19 @@  static inline int ff_thread_once(char *control, void (*routine)(void))
 
 static inline int ff_thread_setname(const char *name)
 {
+    int ret = 0;
+
 #if HAVE_PRCTL
-    return AVERROR(prctl(PR_SET_NAME, name));
+    ret = AVERROR(prctl(PR_SET_NAME, name));
+#elif HAVE_PTHREAD_SETNAME_NP
+    ret = AVERROR(pthread_setname_np(pthread_self(), name));
+#elif HAVE_PTHREAD_SET_NAME_NP
+    pthread_set_name_np(pthread_self(), name);
+#else
+    ret = AVERROR(ENOSYS);
 #endif
 
-    return AVERROR(ENOSYS);
+    return ret;
 }
 
 #endif /* AVUTIL_THREAD_H */