(mc_time_elapsed): add new function to detect elapsed time intervals.

The author of initial patch is Egmont Koblinger.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2014-09-10 09:35:23 +04:00
parent be938c611b
commit 89621050e3
2 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,7 @@
#include "lib/vfs/vfs.h"
#include "lib/strutil.h"
#include "lib/util.h"
#include "lib/timer.h"
/*** global variables ****************************************************************************/
@ -1451,3 +1452,28 @@ mc_replace_error (GError ** dest, int code, const char *format, ...)
}
/* --------------------------------------------------------------------------------------------- */
/**
* Returns if the given duration has elapsed since the given timestamp,
* and if it has then updates the timestamp.
*
* @param timestamp the last timestamp in microseconds, updated if the given time elapsed
* @param deleay amount of time in microseconds
* @return TRUE if clock skew detected, FALSE otherwise
*/
gboolean
mc_time_elapsed (guint64 * timestamp, guint64 delay)
{
guint64 now;
now = mc_timer_elapsed (mc_global.timer);
if (now >= *timestamp && now < *timestamp + delay)
return FALSE;
*timestamp = now;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -249,6 +249,8 @@ char *mc_build_filenamev (const char *first_element, va_list args);
void mc_propagate_error (GError ** dest, int code, const char *format, ...);
void mc_replace_error (GError ** dest, int code, const char *format, ...);
gboolean mc_time_elapsed (guint64 * timestamp, guint64 delay);
/*** inline functions **************************************************/
static inline gboolean