[vlc-devel] commit: Add msleep misuse warning ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Sep 4 20:07:41 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Thu Sep 4 21:10:34 2008 +0300| [7cc631ac462df9d6caf7e98af51438956631607e] | committer: Rémi Denis-Courmont
Add msleep misuse warning
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7cc631ac462df9d6caf7e98af51438956631607e
---
src/misc/mtime.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/misc/mtime.c b/src/misc/mtime.c
index 0d1e062..d9cb505 100644
--- a/src/misc/mtime.c
+++ b/src/misc/mtime.c
@@ -360,6 +360,9 @@ void mwait( mtime_t date )
#endif
}
+
+#include "libvlc.h" /* vlc_backtrace() */
+
/**
* Portable usleep(). Cancellation point.
*
@@ -367,6 +370,27 @@ void mwait( mtime_t date )
*/
void msleep( mtime_t delay )
{
+#ifndef NDEBUG
+# if defined (__linux__) || defined (WIN32)
+ /* We assume that proper use of msleep() will not use a constant period...
+ * Media synchronization is likely to use mwait() with at least slight
+ * sleep length variation at microsecond precision. Network protocols
+ * normally have exponential backoffs, or long delays. */
+ static __thread unsigned tick_period = 0;
+ static __thread unsigned tick_frequency = 0;
+ if (tick_period != delay)
+ tick_frequency = 0;
+ tick_frequency++;
+ tick_period = delay;
+ if (delay < (29 * CLOCK_FREQ) && tick_frequency == 20)
+ {
+ fprintf (stderr, "Likely bogus delay(%"PRIu64"µs) ", delay);
+ vlc_backtrace ();
+ }
+ //fprintf (stderr, "%u, %u\n", tick_period, tick_frequency);
+# endif
+#endif
+
#if defined( HAVE_CLOCK_NANOSLEEP )
lldiv_t d = lldiv( delay, 1000000 );
struct timespec ts = { d.quot, d.rem * 1000 };
More information about the vlc-devel
mailing list