[1/2] compat/w32pthreads: use the CONDITION_VARIABLE typedef if available

Message ID 1412820221-3759-1-git-send-email-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Oct. 9, 2014, 2:03 a.m.
This silences warnings about passing arguments from incompatible pointer type
when targeting Windows Vista or newer.

Signed-off-by: James Almer <jamrial@gmail.com>
---
Sent the wrong version earlier, my bad.
The request for testing i made before still stands.

 compat/w32pthreads.h | 23 +++++++++++++----------
 configure            |  2 ++
 2 files changed, 15 insertions(+), 10 deletions(-)

Comments

Timothy Gu Oct. 9, 2014, 3:45 a.m. | #1
On Wed, Oct 8, 2014 at 7:03 PM, James Almer <jamrial@gmail.com> wrote:
> This silences warnings about passing arguments from incompatible pointer type
> when targeting Windows Vista or newer.
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> Sent the wrong version earlier, my bad.
> The request for testing i made before still stands.
>
>  compat/w32pthreads.h | 23 +++++++++++++----------
>  configure            |  2 ++
>  2 files changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
> index d0b90e8..b905a95 100644
> --- a/compat/w32pthreads.h
> +++ b/compat/w32pthreads.h
> @@ -54,12 +54,15 @@ typedef struct pthread_t {
>   * not mutexes */
>  typedef CRITICAL_SECTION pthread_mutex_t;
>
> -/* This is the CONDITIONAL_VARIABLE typedef for using Window's native
> - * conditional variables on kernels 6.0+.
> - * MinGW does not currently have this typedef. */

> +/* This is the CONDITION_VARIABLE typedef for using Window's native

Please fix the Windows' typo while at it.

> + * conditional variables on kernels 6.0+. */
> +#if HAVE_CONDITION_VARIABLE_PTR
> +typedef CONDITION_VARIABLE pthread_cond_t;
> +#else
>  typedef struct pthread_cond_t {
> -    void *ptr;
> +    void *Ptr;
>  } pthread_cond_t;
> +#endif

[...]

Timothy

Patch

diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index d0b90e8..b905a95 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -54,12 +54,15 @@  typedef struct pthread_t {
  * not mutexes */
 typedef CRITICAL_SECTION pthread_mutex_t;
 
-/* This is the CONDITIONAL_VARIABLE typedef for using Window's native
- * conditional variables on kernels 6.0+.
- * MinGW does not currently have this typedef. */
+/* This is the CONDITION_VARIABLE typedef for using Window's native
+ * conditional variables on kernels 6.0+. */
+#if HAVE_CONDITION_VARIABLE_PTR
+typedef CONDITION_VARIABLE pthread_cond_t;
+#else
 typedef struct pthread_cond_t {
-    void *ptr;
+    void *Ptr;
 } pthread_cond_t;
+#endif
 
 /* function pointers to conditional variable API on windows 6.0+ kernels */
 #if _WIN32_WINNT < 0x0600
@@ -158,7 +161,7 @@  static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused
     win32_cond = av_mallocz(sizeof(win32_cond_t));
     if (!win32_cond)
         return;
-    cond->ptr = win32_cond;
+    cond->Ptr = win32_cond;
     win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
     if (!win32_cond->semaphore)
         return;
@@ -172,7 +175,7 @@  static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused
 
 static av_unused void pthread_cond_destroy(pthread_cond_t *cond)
 {
-    win32_cond_t *win32_cond = cond->ptr;
+    win32_cond_t *win32_cond = cond->Ptr;
     /* native condition variables do not destroy */
     if (cond_init)
         return;
@@ -183,12 +186,12 @@  static av_unused void pthread_cond_destroy(pthread_cond_t *cond)
     pthread_mutex_destroy(&win32_cond->mtx_waiter_count);
     pthread_mutex_destroy(&win32_cond->mtx_broadcast);
     av_freep(&win32_cond);
-    cond->ptr = NULL;
+    cond->Ptr = NULL;
 }
 
 static av_unused void pthread_cond_broadcast(pthread_cond_t *cond)
 {
-    win32_cond_t *win32_cond = cond->ptr;
+    win32_cond_t *win32_cond = cond->Ptr;
     int have_waiter;
 
     if (cond_broadcast) {
@@ -219,7 +222,7 @@  static av_unused void pthread_cond_broadcast(pthread_cond_t *cond)
 
 static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
 {
-    win32_cond_t *win32_cond = cond->ptr;
+    win32_cond_t *win32_cond = cond->Ptr;
     int last_waiter;
     if (cond_wait) {
         cond_wait(cond, mutex, INFINITE);
@@ -251,7 +254,7 @@  static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu
 
 static av_unused void pthread_cond_signal(pthread_cond_t *cond)
 {
-    win32_cond_t *win32_cond = cond->ptr;
+    win32_cond_t *win32_cond = cond->Ptr;
     int have_waiter;
     if (cond_signal) {
         cond_signal(cond);
diff --git a/configure b/configure
index d87871e..a82bef7 100755
--- a/configure
+++ b/configure
@@ -1498,6 +1498,7 @@  TOOLCHAIN_FEATURES="
 "
 
 TYPES_LIST="
+    CONDITION_VARIABLE_Ptr
     socklen_t
     struct_addrinfo
     struct_group_source_req
@@ -4088,6 +4089,7 @@  check_func_headers windows.h MapViewOfFile
 check_func_headers windows.h SetConsoleTextAttribute
 check_func_headers windows.h Sleep
 check_func_headers windows.h VirtualAlloc
+check_struct windows.h "CONDITION_VARIABLE" Ptr
 
 check_header direct.h
 check_header dlfcn.h