diff mbox series

[FFmpeg-devel] avformat/udp: support w32pthreads compat

Message ID 20200302133857.12596-1-phunkyfish@gmail.com
State Superseded
Headers show
Series [FFmpeg-devel] avformat/udp: support w32pthreads compat
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork fail Make failed

Commit Message

phunkyfish March 2, 2020, 1:38 p.m. UTC
---
 compat/w32pthreads.h | 10 ++++++++++
 libavformat/udp.c    |  8 +++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Andriy Gelman March 2, 2020, 2:16 p.m. UTC | #1
On Mon, 02. Mar 13:38, phunkyfish wrote:
> ---
>  compat/w32pthreads.h | 10 ++++++++++
>  libavformat/udp.c    |  8 +++++++-
>  2 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
> index 7df33b7da4..64cd40cda4 100644
> --- a/compat/w32pthreads.h
> +++ b/compat/w32pthreads.h
> @@ -63,6 +63,11 @@ typedef CONDITION_VARIABLE pthread_cond_t;
>  #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)
>  #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
>  
> +#undef PTHREAD_CANCEL_ENABLE
> +#undef PTHREAD_CANCEL_DISABLE
> +#define PTHREAD_CANCEL_ENABLE 1
> +#define PTHREAD_CANCEL_DISABLE 0
> +
>  static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
>  {
>      pthread_t *h = (pthread_t*)arg;
> @@ -180,4 +185,9 @@ static inline int pthread_cond_signal(pthread_cond_t *cond)
>      return 0;
>  }
>  
> +static inline int pthread_setcancelstate(int state, int *oldstate)
> +{
> +    return 0;
> +}
> +
>  #endif /* COMPAT_W32PTHREADS_H */
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 23c3773c64..4f42b026cd 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -61,10 +61,16 @@
>  #define IPPROTO_UDPLITE                                  136
>  #endif
>  
> -#if HAVE_PTHREAD_CANCEL

> +#if HAVE_PTHREAD_CANCEL && !defined(HAVE_W32THREADS)
>  #include <pthread.h>
>  #endif

In my config.h HAVE_W32THREADS is defined, but it's set to 0
so it ends up not including the pthread.h header

>  
> +#if HAVE_W32THREADS 
> +#include "compat/w32pthreads.h"
> +#undef HAVE_PTHREAD_CANCEL 
> +#define HAVE_PTHREAD_CANCEL 1
> +#endif
> +
>  #ifndef IPV6_ADD_MEMBERSHIP
>  #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
>  #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
phunkyfish March 2, 2020, 2:43 p.m. UTC | #2
Thanks!

On Mon, 2 Mar 2020 at 14:16, Andriy Gelman <andriy.gelman@gmail.com> wrote:

> On Mon, 02. Mar 13:38, phunkyfish wrote:
> > ---
> >  compat/w32pthreads.h | 10 ++++++++++
> >  libavformat/udp.c    |  8 +++++++-
> >  2 files changed, 17 insertions(+), 1 deletion(-)
> >
> > diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
> > index 7df33b7da4..64cd40cda4 100644
> > --- a/compat/w32pthreads.h
> > +++ b/compat/w32pthreads.h
> > @@ -63,6 +63,11 @@ typedef CONDITION_VARIABLE pthread_cond_t;
> >  #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0,
> 0)
> >  #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
> >
> > +#undef PTHREAD_CANCEL_ENABLE
> > +#undef PTHREAD_CANCEL_DISABLE
> > +#define PTHREAD_CANCEL_ENABLE 1
> > +#define PTHREAD_CANCEL_DISABLE 0
> > +
> >  static av_unused unsigned __stdcall attribute_align_arg
> win32thread_worker(void *arg)
> >  {
> >      pthread_t *h = (pthread_t*)arg;
> > @@ -180,4 +185,9 @@ static inline int pthread_cond_signal(pthread_cond_t
> *cond)
> >      return 0;
> >  }
> >
> > +static inline int pthread_setcancelstate(int state, int *oldstate)
> > +{
> > +    return 0;
> > +}
> > +
> >  #endif /* COMPAT_W32PTHREADS_H */
> > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > index 23c3773c64..4f42b026cd 100644
> > --- a/libavformat/udp.c
> > +++ b/libavformat/udp.c
> > @@ -61,10 +61,16 @@
> >  #define IPPROTO_UDPLITE                                  136
> >  #endif
> >
> > -#if HAVE_PTHREAD_CANCEL
>
> > +#if HAVE_PTHREAD_CANCEL && !defined(HAVE_W32THREADS)
> >  #include <pthread.h>
> >  #endif
>
> In my config.h HAVE_W32THREADS is defined, but it's set to 0
> so it ends up not including the pthread.h header
>
> >
> > +#if HAVE_W32THREADS
> > +#include "compat/w32pthreads.h"
> > +#undef HAVE_PTHREAD_CANCEL
> > +#define HAVE_PTHREAD_CANCEL 1
> > +#endif
> > +
> >  #ifndef IPV6_ADD_MEMBERSHIP
> >  #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
> >  #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
>
> --
> Andriy
>
diff mbox series

Patch

diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index 7df33b7da4..64cd40cda4 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -63,6 +63,11 @@  typedef CONDITION_VARIABLE pthread_cond_t;
 #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0)
 #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE)
 
+#undef PTHREAD_CANCEL_ENABLE
+#undef PTHREAD_CANCEL_DISABLE
+#define PTHREAD_CANCEL_ENABLE 1
+#define PTHREAD_CANCEL_DISABLE 0
+
 static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
 {
     pthread_t *h = (pthread_t*)arg;
@@ -180,4 +185,9 @@  static inline int pthread_cond_signal(pthread_cond_t *cond)
     return 0;
 }
 
+static inline int pthread_setcancelstate(int state, int *oldstate)
+{
+    return 0;
+}
+
 #endif /* COMPAT_W32PTHREADS_H */
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 23c3773c64..4f42b026cd 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -61,10 +61,16 @@ 
 #define IPPROTO_UDPLITE                                  136
 #endif
 
-#if HAVE_PTHREAD_CANCEL
+#if HAVE_PTHREAD_CANCEL && !defined(HAVE_W32THREADS)
 #include <pthread.h>
 #endif
 
+#if HAVE_W32THREADS 
+#include "compat/w32pthreads.h"
+#undef HAVE_PTHREAD_CANCEL 
+#define HAVE_PTHREAD_CANCEL 1
+#endif
+
 #ifndef IPV6_ADD_MEMBERSHIP
 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP