diff --git a/lib/vfs/gc.c b/lib/vfs/gc.c index 75c251099..5090aaacb 100644 --- a/lib/vfs/gc.c +++ b/lib/vfs/gc.c @@ -39,13 +39,12 @@ #include -#include /* For atol() */ -#include -#include /* gettimeofday() */ +#include #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)) diff --git a/tests/lib/mc_realpath.c b/tests/lib/mc_realpath.c index 31415ac85..17f7c2fff 100644 --- a/tests/lib/mc_realpath.c +++ b/tests/lib/mc_realpath.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/mcconfig/config_string.c b/tests/lib/mcconfig/config_string.c index da479de59..b000f1954 100644 --- a/tests/lib/mcconfig/config_string.c +++ b/tests/lib/mcconfig/config_string.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/mcconfig/user_configs_path.c b/tests/lib/mcconfig/user_configs_path.c index a57f98ecb..f343bee91 100644 --- a/tests/lib/mcconfig/user_configs_path.c +++ b/tests/lib/mcconfig/user_configs_path.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/canonicalize_pathname.c b/tests/lib/vfs/canonicalize_pathname.c index 6f2496817..f070fa039 100644 --- a/tests/lib/vfs/canonicalize_pathname.c +++ b/tests/lib/vfs/canonicalize_pathname.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/current_dir.c b/tests/lib/vfs/current_dir.c index 398fc5440..1cb8a710e 100644 --- a/tests/lib/vfs/current_dir.c +++ b/tests/lib/vfs/current_dir.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/path_cmp.c b/tests/lib/vfs/path_cmp.c index 0e19566c7..76be13bc8 100644 --- a/tests/lib/vfs/path_cmp.c +++ b/tests/lib/vfs/path_cmp.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/path_len.c b/tests/lib/vfs/path_len.c index e68176dbc..f9f40fa66 100644 --- a/tests/lib/vfs/path_len.c +++ b/tests/lib/vfs/path_len.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/path_manipulations.c b/tests/lib/vfs/path_manipulations.c index 8887b582a..9bbdd8ae6 100644 --- a/tests/lib/vfs/path_manipulations.c +++ b/tests/lib/vfs/path_manipulations.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/path_recode.c b/tests/lib/vfs/path_recode.c index f53094a3b..1a832e7b5 100644 --- a/tests/lib/vfs/path_recode.c +++ b/tests/lib/vfs/path_recode.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/path_serialize.c b/tests/lib/vfs/path_serialize.c index 8ae2c830b..0bd26f82a 100644 --- a/tests/lib/vfs/path_serialize.c +++ b/tests/lib/vfs/path_serialize.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/relative_cd.c b/tests/lib/vfs/relative_cd.c index bf5d62319..dd131302f 100644 --- a/tests/lib/vfs/relative_cd.c +++ b/tests/lib/vfs/relative_cd.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/tempdir.c b/tests/lib/vfs/tempdir.c index 8c5f3b359..eaefa5fd1 100644 --- a/tests/lib/vfs/tempdir.c +++ b/tests/lib/vfs/tempdir.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_parse_ls_lga.c b/tests/lib/vfs/vfs_parse_ls_lga.c index b1b203af5..0847cc921 100644 --- a/tests/lib/vfs/vfs_parse_ls_lga.c +++ b/tests/lib/vfs/vfs_parse_ls_lga.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_path_from_str_flags.c b/tests/lib/vfs/vfs_path_from_str_flags.c index 5700c7f03..de1a16472 100644 --- a/tests/lib/vfs/vfs_path_from_str_flags.c +++ b/tests/lib/vfs/vfs_path_from_str_flags.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_path_string_convert.c b/tests/lib/vfs/vfs_path_string_convert.c index 3c32471a5..b081120c1 100644 --- a/tests/lib/vfs/vfs_path_string_convert.c +++ b/tests/lib/vfs/vfs_path_string_convert.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_prefix_to_class.c b/tests/lib/vfs/vfs_prefix_to_class.c index 5c7d79723..2a78a4171 100644 --- a/tests/lib/vfs/vfs_prefix_to_class.c +++ b/tests/lib/vfs/vfs_prefix_to_class.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_s_get_path.c b/tests/lib/vfs/vfs_s_get_path.c index 0aa0037b2..44eea436c 100644 --- a/tests/lib/vfs/vfs_s_get_path.c +++ b/tests/lib/vfs/vfs_s_get_path.c @@ -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); } diff --git a/tests/lib/vfs/vfs_setup_cwd.c b/tests/lib/vfs/vfs_setup_cwd.c index 3d408f028..abbaf4372 100644 --- a/tests/lib/vfs/vfs_setup_cwd.c +++ b/tests/lib/vfs/vfs_setup_cwd.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/lib/vfs/vfs_split.c b/tests/lib/vfs/vfs_split.c index 289dbebf8..b0474e29a 100644 --- a/tests/lib/vfs/vfs_split.c +++ b/tests/lib/vfs/vfs_split.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/execute__common.c b/tests/src/execute__common.c index d0ffa83df..4920ed718 100644 --- a/tests/src/execute__common.c +++ b/tests/src/execute__common.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/execute__execute_get_external_cmd_opts_from_config.c b/tests/src/execute__execute_get_external_cmd_opts_from_config.c index 379717d22..01fb3405d 100644 --- a/tests/src/execute__execute_get_external_cmd_opts_from_config.c +++ b/tests/src/execute__execute_get_external_cmd_opts_from_config.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/filemanager/do_cd_command.c b/tests/src/filemanager/do_cd_command.c index 8cc36ce0b..a55380eb8 100644 --- a/tests/src/filemanager/do_cd_command.c +++ b/tests/src/filemanager/do_cd_command.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/filemanager/exec_get_export_variables_ext.c b/tests/src/filemanager/exec_get_export_variables_ext.c index b32b3bfcb..a7a9d98b5 100644 --- a/tests/src/filemanager/exec_get_export_variables_ext.c +++ b/tests/src/filemanager/exec_get_export_variables_ext.c @@ -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); } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/filemanager/filegui_is_wildcarded.c b/tests/src/filemanager/filegui_is_wildcarded.c index b30734ff6..c26267355 100644 --- a/tests/src/filemanager/filegui_is_wildcarded.c +++ b/tests/src/filemanager/filegui_is_wildcarded.c @@ -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); } /* --------------------------------------------------------------------------------------------- */