]> git.sesse.net Git - vlc/blobdiff - src/misc/threads.c
Force fallback to realtime clock when clock selection is not supported...
[vlc] / src / misc / threads.c
index ffd09f683f92708df4529114a33db85edaaee465..780bef8f240c00d71ed28a00c8a5a3ae12f12193 100644 (file)
 #include <vlc/vlc.h>
 
 #include "libvlc.h"
+#include <assert.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
 
 #define VLC_THREADS_UNINITIALIZED  0
 #define VLC_THREADS_PENDING        1
@@ -238,6 +242,7 @@ int __vlc_threads_end( vlc_object_t *p_this )
  *****************************************************************************/
 int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
 {
+    assert( p_this );
     p_mutex->p_this = p_this;
 
 #if defined( PTH_INIT_IN_PTH_H )
@@ -291,7 +296,8 @@ int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
     return B_OK;
 
 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
-#   if defined(DEBUG) && defined(SYS_LINUX)
+# if defined(DEBUG)
+#   if defined(SYS_LINUX)
     {
         /* Create error-checking mutex to detect problems more easily. */
         pthread_mutexattr_t attr;
@@ -303,7 +309,20 @@ int __vlc_mutex_init( vlc_object_t *p_this, vlc_mutex_t *p_mutex )
         pthread_mutexattr_destroy( &attr );
         return( i_result );
     }
+#   else
+    {
+        /* Create error-checking mutex to detect problems more easily. */
+        pthread_mutexattr_t attr;
+        int                 i_result;
+
+        pthread_mutexattr_init( &attr );
+        pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
+        i_result = pthread_mutex_init( &p_mutex->mutex, &attr );
+        pthread_mutexattr_destroy( &attr );
+        return( i_result );
+    }
 #   endif
+# endif
     return pthread_mutex_init( &p_mutex->mutex, NULL );
 
 #elif defined( HAVE_CTHREADS_H )
@@ -455,7 +474,21 @@ int __vlc_cond_init( vlc_object_t *p_this, vlc_cond_t *p_condvar )
     return 0;
 
 #elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
-    return pthread_cond_init( &p_condvar->cond, NULL );
+    pthread_condattr_t attr;
+    int ret;
+
+    ret = pthread_condattr_init (&attr);
+    if (ret)
+        return ret;
+
+# if defined (_POSIX_CLOCK_SELECTION) && (_POSIX_CLOCK_SELECTION - 0 > 0)
+    /* NOTE: This must be the same clock as the one in mtime.c */
+    pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
+# endif
+
+    ret = pthread_cond_init (&p_condvar->cond, &attr);
+    pthread_condattr_destroy (&attr);
+    return ret;
 
 #elif defined( HAVE_CTHREADS_H )
     /* condition_init() */
@@ -665,7 +698,7 @@ int __vlc_thread_create( vlc_object_t *p_this, const char * psz_file, int i_line
         if( b_wait )
         {
             msg_Dbg( p_this, "waiting for thread completion" );
-            vlc_cond_wait( &p_this->object_wait, &p_this->object_lock );
+            vlc_object_wait( p_this );
         }
 
         p_priv->b_thread = VLC_TRUE;
@@ -754,9 +787,7 @@ int __vlc_thread_set_priority( vlc_object_t *p_this, const char * psz_file,
  *****************************************************************************/
 void __vlc_thread_ready( vlc_object_t *p_this )
 {
-    vlc_mutex_lock( &p_this->object_lock );
-    vlc_cond_signal( &p_this->object_wait );
-    vlc_mutex_unlock( &p_this->object_lock );
+    vlc_object_signal( p_this );
 }
 
 /*****************************************************************************