diff mbox series

[FFmpeg-devel] lavu/thread: Check HAVE_PTHREAD_SET_?NAME_NP is defined

Message ID 20240206101552.28897-1-post@frankplowman.com
State New
Headers show
Series [FFmpeg-devel] lavu/thread: Check HAVE_PTHREAD_SET_?NAME_NP is defined | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Frank Plowman Feb. 6, 2024, 10:15 a.m. UTC
From: Frank Plowman <post@frankplowman.com>

Check HAVE_PTHREAD_SETNAME_NP and HAVE_PTHREAD_SET_NAME_NP are defined
before using them in macro conditions.  Gets rid of lots of -Wundef
warnings present when building on MacOS since
fd16d8c68cd7b820eda76c407b0645b7cf470efd.

Signed-off-by: Frank Plowman <post@frankplowman.com>
---
 libavutil/thread.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Andreas Rheinhardt Feb. 6, 2024, 10:23 a.m. UTC | #1
post@frankplowman.com:
> From: Frank Plowman <post@frankplowman.com>
> 
> Check HAVE_PTHREAD_SETNAME_NP and HAVE_PTHREAD_SET_NAME_NP are defined
> before using them in macro conditions.  Gets rid of lots of -Wundef
> warnings present when building on MacOS since
> fd16d8c68cd7b820eda76c407b0645b7cf470efd.
> 
> Signed-off-by: Frank Plowman <post@frankplowman.com>
> ---
>  libavutil/thread.h | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/libavutil/thread.h b/libavutil/thread.h
> index 2c00c7cc35..0200b7b511 100644
> --- a/libavutil/thread.h
> +++ b/libavutil/thread.h
> @@ -26,7 +26,9 @@
>  
>  #if HAVE_PRCTL
>  #include <sys/prctl.h>
> -#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
> +#elif ((defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP) \
> +    || (defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP)) \
> +    && HAVE_PTHREAD_NP_H
>  #include <pthread_np.h>
>  #endif
>  
> @@ -219,7 +221,7 @@ static inline int ff_thread_setname(const char *name)
>  
>  #if HAVE_PRCTL
>      ret = AVERROR(prctl(PR_SET_NAME, name));
> -#elif HAVE_PTHREAD_SETNAME_NP
> +#elif defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP
>  #if defined(__APPLE__)
>      ret = AVERROR(pthread_setname_np(name));
>  #elif defined(__NetBSD__)
> @@ -227,7 +229,7 @@ static inline int ff_thread_setname(const char *name)
>  #else
>      ret = AVERROR(pthread_setname_np(pthread_self(), name));
>  #endif
> -#elif HAVE_PTHREAD_SET_NAME_NP
> +#elif defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP
>      pthread_set_name_np(pthread_self(), name);
>  #else
>      ret = AVERROR(ENOSYS);

You need to rerun configure. Since
fd16d8c68cd7b820eda76c407b0645b7cf470efd running configure will add
HAVE_PTHREAD_SET_NAME_NP and HAVE_PTHREAD_SETNAME_NP to your config.h file.

- Andreas

PS: There is actually a different problem with this:

In file included from ./libavutil/common.h:88,
                 from ./libavutil/avutil.h:301,
                 from ./libavutil/opt.h:31,
                 from libavdevice/sdl2.c:31:
./config.h:340: warning: "HAVE_PTHREAD_SETNAME_NP" redefined
  340 | #define HAVE_PTHREAD_SETNAME_NP 0
      |
In file included from /usr/include/SDL2/SDL_config.h:4,
                 from /usr/include/SDL2/SDL_stdinc.h:31,
                 from /usr/include/SDL2/SDL_main.h:25,
                 from /usr/include/SDL2/SDL.h:32,
                 from libavdevice/sdl2.c:26:
/usr/include/x86_64-linux-gnu/SDL2/_real_SDL_config.h:205: note: this is
the location of the previous definition
  205 | #define HAVE_PTHREAD_SETNAME_NP 1
      |
Frank Plowman Feb. 6, 2024, 10:24 a.m. UTC | #2
On 06/02/2024 11:23, Andreas Rheinhardt wrote:
> post@frankplowman.com:
>> From: Frank Plowman <post@frankplowman.com>
>>
>> Check HAVE_PTHREAD_SETNAME_NP and HAVE_PTHREAD_SET_NAME_NP are defined
>> before using them in macro conditions.  Gets rid of lots of -Wundef
>> warnings present when building on MacOS since
>> fd16d8c68cd7b820eda76c407b0645b7cf470efd.
>>
>> Signed-off-by: Frank Plowman <post@frankplowman.com>
>> ---
>>  libavutil/thread.h | 8 +++++---
>>  1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavutil/thread.h b/libavutil/thread.h
>> index 2c00c7cc35..0200b7b511 100644
>> --- a/libavutil/thread.h
>> +++ b/libavutil/thread.h
>> @@ -26,7 +26,9 @@
>>  
>>  #if HAVE_PRCTL
>>  #include <sys/prctl.h>
>> -#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
>> +#elif ((defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP) \
>> +    || (defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP)) \
>> +    && HAVE_PTHREAD_NP_H
>>  #include <pthread_np.h>
>>  #endif
>>  
>> @@ -219,7 +221,7 @@ static inline int ff_thread_setname(const char *name)
>>  
>>  #if HAVE_PRCTL
>>      ret = AVERROR(prctl(PR_SET_NAME, name));
>> -#elif HAVE_PTHREAD_SETNAME_NP
>> +#elif defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP
>>  #if defined(__APPLE__)
>>      ret = AVERROR(pthread_setname_np(name));
>>  #elif defined(__NetBSD__)
>> @@ -227,7 +229,7 @@ static inline int ff_thread_setname(const char *name)
>>  #else
>>      ret = AVERROR(pthread_setname_np(pthread_self(), name));
>>  #endif
>> -#elif HAVE_PTHREAD_SET_NAME_NP
>> +#elif defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP
>>      pthread_set_name_np(pthread_self(), name);
>>  #else
>>      ret = AVERROR(ENOSYS);
> 
> You need to rerun configure. Since
> fd16d8c68cd7b820eda76c407b0645b7cf470efd running configure will add
> HAVE_PTHREAD_SET_NAME_NP and HAVE_PTHREAD_SETNAME_NP to your config.h file.

Ah, I see thanks.  Sorry for the noise!
diff mbox series

Patch

diff --git a/libavutil/thread.h b/libavutil/thread.h
index 2c00c7cc35..0200b7b511 100644
--- a/libavutil/thread.h
+++ b/libavutil/thread.h
@@ -26,7 +26,9 @@ 
 
 #if HAVE_PRCTL
 #include <sys/prctl.h>
-#elif (HAVE_PTHREAD_SETNAME_NP || HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_NP_H
+#elif ((defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP) \
+    || (defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP)) \
+    && HAVE_PTHREAD_NP_H
 #include <pthread_np.h>
 #endif
 
@@ -219,7 +221,7 @@  static inline int ff_thread_setname(const char *name)
 
 #if HAVE_PRCTL
     ret = AVERROR(prctl(PR_SET_NAME, name));
-#elif HAVE_PTHREAD_SETNAME_NP
+#elif defined(HAVE_PTHREAD_SETNAME_NP) && HAVE_PTHREAD_SETNAME_NP
 #if defined(__APPLE__)
     ret = AVERROR(pthread_setname_np(name));
 #elif defined(__NetBSD__)
@@ -227,7 +229,7 @@  static inline int ff_thread_setname(const char *name)
 #else
     ret = AVERROR(pthread_setname_np(pthread_self(), name));
 #endif
-#elif HAVE_PTHREAD_SET_NAME_NP
+#elif defined(HAVE_PTHREAD_SET_NAME_NP) && HAVE_PTHREAD_SET_NAME_NP
     pthread_set_name_np(pthread_self(), name);
 #else
     ret = AVERROR(ENOSYS);