]> git.sesse.net Git - vlc/commitdiff
Make sure we use the same clock for condition variable
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 15 Sep 2007 16:05:36 +0000 (16:05 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 15 Sep 2007 16:05:36 +0000 (16:05 +0000)
Otherwise, it'll screw up completely when we add vlc_cond_timedwait

include/vlc_threads_funcs.h
src/misc/threads.c

index b4822bce990a505f017adcaa6fd6f628135350ba..e6e09e2d36e81c1253b80dd11b89fcaa13bfbaad 100644 (file)
@@ -504,12 +504,10 @@ static inline int __vlc_cond_wait( const char * psz_file, int i_line,
 
 #   ifdef DEBUG
     /* In debug mode, timeout */
-    struct timeval now;
     struct timespec timeout;
 
-    gettimeofday( &now, NULL );
-    timeout.tv_sec = now.tv_sec + THREAD_COND_TIMEOUT;
-    timeout.tv_nsec = now.tv_usec * 1000;
+    clock_gettime( CLOCK_MONOTONIC, &now );
+    timeout.tv_sec += THREAD_COND_TIMEOUT;
 
     i_result = pthread_cond_timedwait( &p_condvar->cond, &p_mutex->mutex,
                                        &timeout );
index 26c7000708915ef78ab19f189e40037633e96736..1fa748975a1beb51e693360ec9189bfffd440714 100644 (file)
@@ -457,7 +457,19 @@ 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;
+
+    /* This must be the same clock as the one in mtime.c */
+    pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
+
+    ret = pthread_cond_init (&p_condvar->cond, &attr);
+    pthread_condattr_destroy (&attr);
+    return ret;
 
 #elif defined( HAVE_CTHREADS_H )
     /* condition_init() */