[vlc-devel] commit: mwait/mdate: remove cached_time - not thread-safe ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon May 19 19:41:25 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Mon May 19 20:42:48 2008 +0300| [a056e64e5142c36651a7a15ed5143075266e3e06]

mwait/mdate: remove cached_time - not thread-safe

Could go badly wrong on platforms without atomic 64-bits access

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

 src/misc/mtime.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/misc/mtime.c b/src/misc/mtime.c
index b7beef5..7949096 100644
--- a/src/misc/mtime.c
+++ b/src/misc/mtime.c
@@ -172,8 +172,6 @@ static inline unsigned mprec( void )
 #endif
 }
 
-static volatile mtime_t cached_time = 0;
-
 /**
  * Return high precision date
  *
@@ -313,7 +311,7 @@ mtime_t mdate( void )
     res = (mtime_t) tv_date.tv_sec * 1000000 + (mtime_t) tv_date.tv_usec;
 #endif
 
-    return cached_time = res;
+    return res;
 }
 
 /**
@@ -327,9 +325,8 @@ mtime_t mdate( void )
 void mwait( mtime_t date )
 {
     /* If the deadline is already elapsed, or within the clock precision,
-     * do not even bother the clock. */
-    if( ( date - cached_time ) < (mtime_t)mprec() ) // OK: mtime_t is signed
-        return;
+     * do not even bother the system timer. */
+    date -= mprec();
 
 #if 0 && defined (HAVE_CLOCK_NANOSLEEP)
     lldiv_t d = lldiv( date, 1000000 );
@@ -360,8 +357,6 @@ void mwait( mtime_t date )
  */
 void msleep( mtime_t delay )
 {
-    mtime_t earlier = cached_time;
-
 #if defined( HAVE_CLOCK_NANOSLEEP )
     lldiv_t d = lldiv( delay, 1000000 );
     struct timespec ts = { d.quot, d.rem * 1000 };
@@ -398,10 +393,6 @@ void msleep( mtime_t delay )
      * or clock_nanosleep() if this is an issue. */
     select( 0, NULL, NULL, NULL, &tv_delay );
 #endif
-
-    earlier += delay;
-    if( cached_time < earlier )
-        cached_time = earlier;
 }
 
 /*




More information about the vlc-devel mailing list