[vlc-commits] win32: use futex-based semaphore (Windows 8+)

Rémi Denis-Courmont git at videolan.org
Wed Jun 1 21:57:09 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jun  1 00:29:59 2016 +0300| [dbfafd71bd7cb26cf1d92c961ab2ae38d0ee263d] | committer: Rémi Denis-Courmont

win32: use futex-based semaphore (Windows 8+)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dbfafd71bd7cb26cf1d92c961ab2ae38d0ee263d
---

 include/vlc_threads.h |   12 ++++++++----
 src/misc/threads.c    |    4 ++++
 src/win32/thread.c    |   12 +++++++-----
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index d3ea0ac..b0872bc 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -67,10 +67,14 @@ typedef struct
         CRITICAL_SECTION mutex;
     };
 } vlc_mutex_t;
-#define VLC_STATIC_MUTEX { false, { { false, 0 } } }
-#define LIBVLC_NEED_CONDVAR
-typedef HANDLE vlc_sem_t;
-#define LIBVLC_NEED_RWLOCK
+# define VLC_STATIC_MUTEX { false, { { false, 0 } } }
+# define LIBVLC_NEED_CONDVAR
+typedef union
+{
+    unsigned value;
+    HANDLE handle;
+} vlc_sem_t;
+# define LIBVLC_NEED_RWLOCK
 typedef struct vlc_threadvar *vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 6451274..eec58a3 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -69,6 +69,10 @@ static void vlc_cancel_addr_finish(void *addr)
     /* Act on cancellation as potential wake-up source */
     vlc_testcancel();
 }
+
+# if defined (_WIN32) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
+#  define LIBVLC_NEED_SEMAPHORE
+# endif
 #endif
 
 #ifdef LIBVLC_NEED_SLEEP
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 8d74d6f..49e533e 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -216,21 +216,22 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
 }
 
 /*** Semaphore ***/
+#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
 void vlc_sem_init (vlc_sem_t *sem, unsigned value)
 {
-    *sem = CreateSemaphore (NULL, value, 0x7fffffff, NULL);
-    if (*sem == NULL)
+    sem->handle = CreateSemaphore(NULL, value, 0x7fffffff, NULL);
+    if (sem->handle == NULL)
         abort ();
 }
 
 void vlc_sem_destroy (vlc_sem_t *sem)
 {
-    CloseHandle (*sem);
+    CloseHandle(sem->handle);
 }
 
 int vlc_sem_post (vlc_sem_t *sem)
 {
-    ReleaseSemaphore (*sem, 1, NULL);
+    ReleaseSemaphore(sem->handle, 1, NULL);
     return 0; /* FIXME */
 }
 
@@ -241,10 +242,11 @@ void vlc_sem_wait (vlc_sem_t *sem)
     do
     {
         vlc_testcancel ();
-        result = vlc_WaitForSingleObject (*sem, INFINITE);
+        result = vlc_WaitForSingleObject(sem->value, INFINITE);
     }
     while (result == WAIT_IO_COMPLETION);
 }
+#endif
 
 /*** Thread-specific variables (TLS) ***/
 struct vlc_threadvar



More information about the vlc-commits mailing list