mirror of https://github.com/MidnightCommander/mc
VFS GC: use mc_timer.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
7a58b5e498
commit
a94dd7d2de
31
lib/vfs/gc.c
31
lib/vfs/gc.c
|
@ -39,13 +39,12 @@
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h> /* For atol() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h> /* gettimeofday() */
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/event.h"
|
||||
#include "lib/util.h" /* MC_PTR_FREE */
|
||||
#include "lib/timer.h"
|
||||
|
||||
#include "vfs.h"
|
||||
#include "utilvfs.h"
|
||||
|
@ -99,7 +98,7 @@ struct vfs_stamping
|
|||
{
|
||||
struct vfs_class *v;
|
||||
vfsid id;
|
||||
struct timeval time;
|
||||
guint64 time;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
@ -110,17 +109,6 @@ static GSList *stamps = NULL;
|
|||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Compare two timeval structures. Return TRUE if t1 is less than t2. */
|
||||
|
||||
static gboolean
|
||||
timeoutcmp (const struct timeval *t1, const struct timeval *t2)
|
||||
{
|
||||
return ((t1->tv_sec < t2->tv_sec)
|
||||
|| ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec <= t2->tv_usec)));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gint
|
||||
vfs_stamp_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
|
@ -142,7 +130,7 @@ vfs_addstamp (struct vfs_class *v, vfsid id)
|
|||
stamp = g_new (struct vfs_stamping, 1);
|
||||
stamp->v = v;
|
||||
stamp->id = id;
|
||||
gettimeofday (&(stamp->time), NULL);
|
||||
stamp->time = mc_timer_elapsed (mc_global.timer);
|
||||
|
||||
stamps = g_slist_append (stamps, stamp);
|
||||
}
|
||||
|
@ -165,7 +153,7 @@ vfs_stamp (struct vfs_class *v, vfsid id)
|
|||
stamp = g_slist_find_custom (stamps, &what, vfs_stamp_compare);
|
||||
if (stamp != NULL && stamp->data != NULL)
|
||||
{
|
||||
gettimeofday (&(VFS_STAMPING (stamp->data)->time), NULL);
|
||||
VFS_STAMPING (stamp->data)->time = mc_timer_elapsed (mc_global.timer);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
|
@ -251,7 +239,7 @@ void
|
|||
vfs_expire (gboolean now)
|
||||
{
|
||||
static gboolean locked = FALSE;
|
||||
struct timeval curr_time, exp_time;
|
||||
guint64 curr_time, exp_time;
|
||||
GSList *stamp;
|
||||
|
||||
/* Avoid recursive invocation, e.g. when one of the free functions
|
||||
|
@ -260,9 +248,8 @@ vfs_expire (gboolean now)
|
|||
return;
|
||||
locked = TRUE;
|
||||
|
||||
gettimeofday (&curr_time, NULL);
|
||||
exp_time.tv_sec = curr_time.tv_sec - vfs_timeout;
|
||||
exp_time.tv_usec = curr_time.tv_usec;
|
||||
curr_time = mc_timer_elapsed (mc_global.timer);
|
||||
exp_time = curr_time - vfs_timeout * G_USEC_PER_SEC;
|
||||
|
||||
if (now)
|
||||
{
|
||||
|
@ -282,7 +269,7 @@ vfs_expire (gboolean now)
|
|||
stamping->v->free (stamping->id);
|
||||
MC_PTR_FREE (stamp->data);
|
||||
}
|
||||
else if (timeoutcmp (&stamping->time, &exp_time))
|
||||
else if (stamping->time <= exp_time)
|
||||
{
|
||||
/* update timestamp of VFS that is in use, or free unused VFS */
|
||||
if (stamping->v->nothingisopen != NULL && !stamping->v->nothingisopen (stamping->id))
|
||||
|
|
|
@ -43,6 +43,7 @@ static char resolved_path[PATH_MAX];
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
vfs_init ();
|
||||
vfs_init_localfs ();
|
||||
|
@ -55,6 +56,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -79,6 +79,7 @@ config_object__deinit (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings ("KOI8-R");
|
||||
vfs_init ();
|
||||
vfs_init_localfs ();
|
||||
|
@ -96,6 +97,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -59,6 +59,7 @@ setup (void)
|
|||
g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
|
||||
g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
|
||||
#endif
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings ("UTF-8");
|
||||
vfs_init ();
|
||||
vfs_init_localfs ();
|
||||
|
@ -72,6 +73,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -45,6 +45,7 @@ static struct vfs_class vfs_test_ops;
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -71,7 +72,9 @@ teardown (void)
|
|||
#endif
|
||||
|
||||
vfs_shut ();
|
||||
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -55,6 +55,7 @@ test_chdir (const vfs_path_t * vpath)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -74,6 +75,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -66,6 +67,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -66,6 +67,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -60,7 +60,7 @@ init_test_classes (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -87,6 +87,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -65,6 +65,7 @@ teardown (void)
|
|||
static void
|
||||
test_init_vfs (const char *encoding)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (encoding);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -85,6 +86,7 @@ test_deinit_vfs (void)
|
|||
free_codepages_list ();
|
||||
str_uninit_strings ();
|
||||
vfs_shut ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -45,6 +45,7 @@ static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -78,6 +79,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -73,6 +73,7 @@ test_chdir__deinit (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -101,6 +102,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -60,6 +61,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -55,6 +55,7 @@ setup (void)
|
|||
{
|
||||
static struct stat initstat;
|
||||
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -80,6 +81,7 @@ teardown (void)
|
|||
vfs_s_free_entry (vfs_test_ops1, vfs_root_entry);
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -46,6 +46,7 @@ mc_config_get_home_dir (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -61,6 +62,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -48,6 +48,7 @@ static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -81,6 +82,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -55,6 +55,7 @@ test_which (struct vfs_class *me, const char *path)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -80,6 +81,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -82,6 +82,7 @@ test1_mock_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -109,6 +110,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ mc_stat (const vfs_path_t * vpath, struct stat *my_stat)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -91,6 +92,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -41,6 +41,7 @@ static struct vfs_class vfs_test_ops1, vfs_test_ops2, vfs_test_ops3;
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -65,6 +66,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -238,6 +238,7 @@ mc_ungetlocalcopy__deinit (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
vfs_init ();
|
||||
vfs_init_localfs ();
|
||||
|
@ -266,6 +267,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -95,6 +95,7 @@ mc_config_get_string__deinit (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
vfs_init ();
|
||||
vfs_init_localfs ();
|
||||
|
@ -113,6 +114,7 @@ teardown (void)
|
|||
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -80,6 +80,7 @@ mc_config_get_home_dir (void)
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -97,6 +98,7 @@ teardown (void)
|
|||
vfs_path_free (do_cd__new_dir_vpath__captured);
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -61,6 +62,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
static void
|
||||
setup (void)
|
||||
{
|
||||
mc_global.timer = mc_timer_new ();
|
||||
str_init_strings (NULL);
|
||||
|
||||
vfs_init ();
|
||||
|
@ -53,6 +54,7 @@ teardown (void)
|
|||
{
|
||||
vfs_shut ();
|
||||
str_uninit_strings ();
|
||||
mc_timer_destroy (mc_global.timer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue