Commit e516ddb1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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

parent 6db8a5e0
......@@ -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
*****************************************************************************/
......
......@@ -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 ) );
......
......@@ -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 ) \
......
......@@ -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,
......
......@@ -314,6 +314,7 @@ mtime_t mdate( void )
return res;
}
#undef mwait
/**
* Wait for a date
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment