mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
(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:
parent
be938c611b
commit
89621050e3
26
lib/util.c
26
lib/util.c
@ -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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user