[vlc-devel] commit: Rework delay checking, use it for net_Accept, add deadline checks ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Sep 7 11:19:17 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sun Sep  7 12:09:18 2008 +0300| [e516ddb1ca69202f576d6e7020c9f9b2c90b8890] | committer: Rémi Denis-Courmont 

Rework delay checking, use it for net_Accept, add deadline checks

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

 include/vlc_mtime.h   |   36 +++++++++++++++++++++++++++---------
 include/vlc_network.h |    3 ++-
 include/vlc_objects.h |    2 +-
 include/vlc_threads.h |    4 ++--
 src/misc/mtime.c      |    1 +
 5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/include/vlc_mtime.h b/include/vlc_mtime.h
index 08262a7..e51c639 100644
--- a/include/vlc_mtime.h
+++ b/include/vlc_mtime.h
@@ -80,31 +80,49 @@ static
 __attribute__((unused))
 __attribute__((noinline))
 __attribute__((error("sorry, cannot sleep for such short a time")))
-void impossible_msleep( mtime_t delay )
+mtime_t impossible_delay( mtime_t delay )
 {
     (void) delay;
-    msleep( VLC_HARD_MIN_SLEEP );
+    return VLC_HARD_MIN_SLEEP;
 }
 
 static
 __attribute__((unused))
 __attribute__((noinline))
-__attribute__((warning("use proper event handling instead")))
-void bad_msleep( mtime_t delay )
+__attribute__((warning("use proper event handling instead of short delay")))
+mtime_t harmful_delay( mtime_t delay )
 {
-    msleep( delay );
+    return delay;
 }
 
-# define msleep( d ) \
+# define check_delay( d ) \
     ((__builtin_constant_p(d < VLC_HARD_MIN_SLEEP) \
    && (d < VLC_HARD_MIN_SLEEP)) \
-       ? impossible_msleep(d) \
+       ? impossible_delay(d) \
        : ((__builtin_constant_p(d < VLC_SOFT_MIN_SLEEP) \
        && (d < VLC_SOFT_MIN_SLEEP)) \
-           ? bad_msleep(d) \
-           : msleep(d)))
+           ? harmful_delay(d) \
+           : d))
+
+static
+__attribute__((unused))
+__attribute__((noinline))
+__attribute__((error("deadlines can not be constant")))
+mtime_t impossible_deadline( mtime_t deadline )
+{
+    return deadline;
+}
+
+# define check_deadline( d ) \
+    (__builtin_constant_p(d) ? impossible_deadline(d) : d)
+#else
+# define check_delay(d) (d)
+# define check_deadline(d) (d)
 #endif
 
+#define msleep(d) msleep(check_delay(d))
+#define mwait(d) mwait(check_deadline(d))
+
 /*****************************************************************************
  * date_t: date incrementation without long-term rounding errors
  *****************************************************************************/
diff --git a/include/vlc_network.h b/include/vlc_network.h
index 5c4b1dc..d32cf5c 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -107,8 +107,9 @@ static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int por
 
 VLC_EXPORT( int, net_AcceptSingle, (vlc_object_t *obj, int lfd) );
 
-#define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
 VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
+#define net_Accept(a, b, c) \
+      __net_Accept(VLC_OBJECT(a), b, c ? check_delay(c) : 0)
 
 #define net_ConnectDgram(a, b, c, d, e ) __net_ConnectDgram(VLC_OBJECT(a), b, c, d, e)
 VLC_EXPORT( int, __net_ConnectDgram, ( vlc_object_t *p_this, const char *psz_host, int i_port, int hlim, int proto ) );
diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index bf568ed..67f26da 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -139,7 +139,7 @@ VLC_EXPORT( void, __vlc_object_wait, ( vlc_object_t * ) );
 
 VLC_EXPORT( int, __vlc_object_timedwait, ( vlc_object_t *, mtime_t ) );
 #define vlc_object_timedwait( obj, d ) \
-    __vlc_object_timedwait( VLC_OBJECT( obj ), d )
+    __vlc_object_timedwait( VLC_OBJECT( obj ), check_deadline(d) )
 
 VLC_EXPORT( void, __vlc_object_signal_unlocked, ( vlc_object_t * ) );
 #define vlc_object_signal_unlocked( obj ) \
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 3afadfa..392db06 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -411,8 +411,8 @@ static inline void __vlc_cond_wait( const char * psz_file, int i_line,
  *****************************************************************************
  * Returns 0 if object signaled, an error code in case of timeout or error.
  *****************************************************************************/
-#define vlc_cond_timedwait( P_COND, P_MUTEX, DEADLINE )                      \
-    __vlc_cond_timedwait( __FILE__, __LINE__, P_COND, P_MUTEX, DEADLINE  )
+#define vlc_cond_timedwait( c, m, d ) \
+    __vlc_cond_timedwait( __FILE__, __LINE__, c, m, check_deadline(d) )
 
 static inline int __vlc_cond_timedwait( const char * psz_file, int i_line,
                                         vlc_cond_t *p_condvar,
diff --git a/src/misc/mtime.c b/src/misc/mtime.c
index afa5705..37a28f9 100644
--- a/src/misc/mtime.c
+++ b/src/misc/mtime.c
@@ -314,6 +314,7 @@ mtime_t mdate( void )
     return res;
 }
 
+#undef mwait
 /**
  * Wait for a date
  *




More information about the vlc-devel mailing list