]> git.sesse.net Git - vlc/blobdiff - include/vlc_threads.h
decoder: fix data race in input_DecoderFrameNext()
[vlc] / include / vlc_threads.h
index 1197b55cd486cd605633dbdbfe5f2e014c560068..d3f021bb40b1a1bda32fa79aabc3066139f161f2 100644 (file)
@@ -34,7 +34,7 @@
  *
  */
 
-#if defined (WIN32)
+#if defined (_WIN32)
 # include <process.h>
 # ifndef ETIMEDOUT
 #  define ETIMEDOUT 10060 /* This is the value in winsock.h. */
@@ -155,8 +155,12 @@ typedef struct vlc_timer *vlc_timer_t;
 typedef pthread_t       vlc_thread_t;
 typedef pthread_mutex_t vlc_mutex_t;
 #define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
-typedef pthread_cond_t  vlc_cond_t;
-#define VLC_STATIC_COND  PTHREAD_COND_INITIALIZER
+typedef struct
+{
+    pthread_cond_t cond;
+    unsigned clock;
+} vlc_cond_t;
+#define VLC_STATIC_COND  { PTHREAD_COND_INITIALIZER, 0 }
 typedef semaphore_t     vlc_sem_t;
 typedef pthread_rwlock_t vlc_rwlock_t;
 #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
@@ -382,21 +386,39 @@ struct vlc_cleanup_t
         vlc_cleanup_data.proc (vlc_cleanup_data.data); \
     } while (0)
 
-#endif /* !LIBVLC_USE_PTHREAD_CLEANUO */
+#endif /* !LIBVLC_USE_PTHREAD_CLEANUP */
 
 #ifndef LIBVLC_USE_PTHREAD_CANCEL
 /* poll() with cancellation */
+# ifdef __OS2__
+static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
+{
+    static int (*vlc_poll_os2)(struct pollfd *, unsigned, int) = NULL;
+
+    if (!vlc_poll_os2)
+    {
+        HMODULE hmod;
+        CHAR szFailed[CCHMAXPATH];
+
+        if (DosLoadModule(szFailed, sizeof(szFailed), "vlccore", &hmod))
+            return -1;
+
+        if (DosQueryProcAddr(hmod, 0, "_vlc_poll_os2", (PFN *)&vlc_poll_os2))
+            return -1;
+    }
+
+    return (*vlc_poll_os2)(fds, nfds, timeout);
+}
+# else
 static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 {
     int val;
 
     do
     {
-        int ugly_timeout = 50;
-        if (timeout >= 50)
-            timeout -= 50;
-        else if ((unsigned)timeout < 50u)
-            ugly_timeout = timeout;
+        int ugly_timeout = ((unsigned)timeout >= 50) ? 50 : timeout;
+        if (timeout >= 0)
+            timeout -= ugly_timeout;
 
         vlc_testcancel ();
         val = poll (fds, nfds, ugly_timeout);
@@ -405,6 +427,8 @@ static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 
     return val;
 }
+# endif
+
 # define poll(u,n,t) vlc_poll(u, n, t)
 
 #endif /* LIBVLC_USE_PTHREAD_CANCEL */