Drop mc_timer. Use g_get_real_time() instead.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-11-22 15:40:18 +03:00
parent 4a83daacc4
commit 78893d85b8
40 changed files with 19 additions and 222 deletions

View File

@ -42,8 +42,7 @@ libmc_la_SOURCES = \
serialize.c serialize.h \
shell.c shell.h \
stat-size.h \
timefmt.c timefmt.h \
timer.c timer.h
timefmt.c timefmt.h
if USE_MAINTAINER_MODE
libmc_la_SOURCES += logging.c logging.h

View File

@ -31,7 +31,6 @@
#include <config.h>
#include "global.h"
#include "lib/timer.h"
/* *INDENT-OFF* */
#ifdef ENABLE_SUBSHELL
@ -51,7 +50,6 @@
mc_global_t mc_global = {
.mc_run_mode = MC_RUN_FULL,
.run_from_parent_mc = FALSE,
.timer = NULL,
.midnight_shutdown = FALSE,
.sysconfig_dir = NULL,

View File

@ -148,8 +148,6 @@
#define DEFAULT_CHARSET "ASCII"
#include "lib/timer.h" /* mc_timer_t */
/*** enums ***************************************************************************************/
/* run mode and params */
@ -167,8 +165,6 @@ typedef struct
{
mc_run_mode_t mc_run_mode;
gboolean run_from_parent_mc;
/* global timer */
mc_timer_t *timer;
/* Used so that widgets know if they are being destroyed or shut down */
gboolean midnight_shutdown;

View File

@ -1,106 +0,0 @@
/*
Simple timer for the Midnight Commander.
Copyright (C) 2013-2020
Free Software Foundation, Inc.
Written by:
Andrew Borodin 2013
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* \brief Source: simple timer
*/
#include <config.h>
#include "lib/global.h"
#include "lib/timer.h"
/*** global variables ****************************************************************************/
/**
* mc_timer_t:
*
* Opaque datatype that records a start time.
* #mc_timer_t records a start time, and counts microseconds elapsed since
* that time.
**/
struct mc_timer_t
{
guint64 start;
};
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/**
* Creates a new timer, and starts timing.
*
* @return: a new #mc_timer_t.
**/
mc_timer_t *
mc_timer_new (void)
{
mc_timer_t *timer;
timer = g_new (mc_timer_t, 1);
timer->start = (guint64) g_get_real_time ();
return timer;
}
/* --------------------------------------------------------------------------------------------- */
/**
* Destroys a timer, freeing associated resources.
*
* @timer: an #mc_timer_t to destroy.
**/
void
mc_timer_destroy (mc_timer_t * timer)
{
g_free (timer);
}
/* --------------------------------------------------------------------------------------------- */
/**
* Obtains the time since the timer was started.
*
* @timer: an #mc_timer_t.
*
* @return: microseconds elapsed, the time since the timer was started
*
**/
guint64
mc_timer_elapsed (const mc_timer_t * timer)
{
return ((guint64) g_get_real_time () - timer->start);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1,27 +0,0 @@
/** \file timer.h
* \brief Header: simple timer
*/
#ifndef MC_TIMER_H
#define MC_TIMER_H
/*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
struct mc_timer_t;
typedef struct mc_timer_t mc_timer_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
mc_timer_t *mc_timer_new (void);
void mc_timer_destroy (mc_timer_t * timer);
guint64 mc_timer_elapsed (const mc_timer_t * timer);
/*** inline functions **************************************************/
#endif /* MC_TIMER_H */

View File

@ -51,7 +51,6 @@
#include "lib/vfs/vfs.h"
#include "lib/strutil.h"
#include "lib/util.h"
#include "lib/timer.h"
/*** global variables ****************************************************************************/
@ -1518,11 +1517,11 @@ mc_replace_error (GError ** dest, int code, const char *format, ...)
* @return TRUE if clock skew detected, FALSE otherwise
*/
gboolean
mc_time_elapsed (guint64 * timestamp, guint64 delay)
mc_time_elapsed (gint64 * timestamp, gint64 delay)
{
guint64 now;
gint64 now;
now = mc_timer_elapsed (mc_global.timer);
now = g_get_real_time ();
if (now >= *timestamp && now < *timestamp + delay)
return FALSE;

View File

@ -272,7 +272,7 @@ void mc_propagate_error (GError ** dest, int code, const char *format, ...) G_GN
void mc_replace_error (GError ** dest, int code, const char *format, ...) G_GNUC_PRINTF (3, 4);
/* *INDENT-ON* */
gboolean mc_time_elapsed (guint64 * timestamp, guint64 delay);
gboolean mc_time_elapsed (gint64 * timestamp, gint64 delay);
/*** inline functions **************************************************/

View File

@ -583,17 +583,17 @@ void
status_msg_init (status_msg_t * sm, const char *title, double delay, status_msg_cb init_cb,
status_msg_update_cb update_cb, status_msg_cb deinit_cb)
{
guint64 start;
gint64 start;
/* repaint screen to remove previous finished dialog */
mc_refresh ();
start = mc_timer_elapsed (mc_global.timer);
start = g_get_real_time ();
sm->dlg = dlg_create (TRUE, 0, 0, 7, MIN (MAX (40, COLS / 2), COLS), WPOS_CENTER, FALSE,
dialog_colors, NULL, NULL, NULL, title);
sm->start = start;
sm->delay = (guint64) (delay * G_USEC_PER_SEC);
sm->delay = (gint64) (delay * G_USEC_PER_SEC);
sm->block = FALSE;
sm->init = init_cb;
@ -658,7 +658,7 @@ status_msg_common_update (status_msg_t * sm)
/* dialog is not shown yet */
/* do not change sm->start */
guint64 start = sm->start;
gint64 start = sm->start;
if (mc_time_elapsed (&start, sm->delay))
dlg_init (sm->dlg);

View File

@ -5,8 +5,6 @@
#ifndef MC__WTOOLS_H
#define MC__WTOOLS_H
#include "lib/timer.h"
/*** typedefs(not structures) and defined constants **********************************************/
/* Pass this as def_text to request a password */
@ -42,8 +40,8 @@ enum
struct status_msg_t
{
WDialog *dlg; /* pointer to status message dialog */
guint64 start; /* start time in microseconds */
guint64 delay; /* delay before raise the 'dlg' in microseconds */
gint64 start; /* start time in microseconds */
gint64 delay; /* delay before raise the 'dlg' in microseconds */
gboolean block; /* how to get event using tty_get_event() */
status_msg_cb init; /* callback to init derived classes */

View File

@ -616,9 +616,9 @@ do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds
size_t * dir_count, size_t * ret_marked, uintmax_t * ret_total,
mc_stat_fn stat_func)
{
static guint64 timestamp = 0;
static gint64 timestamp = 0;
/* update with 25 FPS rate */
static const guint64 delay = G_USEC_PER_SEC / 25;
static const gint64 delay = G_USEC_PER_SEC / 25;
status_msg_t *sm = STATUS_MSG (dsm);
int res;

View File

@ -1158,9 +1158,9 @@ file_progress_show_target (file_op_context_t * ctx, const vfs_path_t * vpath)
gboolean
file_progress_show_deleting (file_op_context_t * ctx, const char *s, size_t * count)
{
static guint64 timestamp = 0;
static gint64 timestamp = 0;
/* update with 25 FPS rate */
static const guint64 delay = G_USEC_PER_SEC / 25;
static const gint64 delay = G_USEC_PER_SEC / 25;
gboolean ret;

View File

@ -1027,9 +1027,9 @@ set_hintbar (const char *str)
void
rotate_dash (gboolean show)
{
static guint64 timestamp = 0;
static gint64 timestamp = 0;
/* update with 10 FPS rate */
static const guint64 delay = G_USEC_PER_SEC / 10;
static const gint64 delay = G_USEC_PER_SEC / 10;
const Widget *w = CONST_WIDGET (midnight_dlg);

View File

@ -1666,8 +1666,8 @@ midnight_set_buttonbar (WButtonBar * b)
char *
get_random_hint (gboolean force)
{
static const guint64 update_period = 60 * G_USEC_PER_SEC;
static guint64 tv = 0;
static const gint64 update_period = 60 * G_USEC_PER_SEC;
static gint64 tv = 0;
char *data, *result = NULL, *eop;
size_t len, start;

View File

@ -49,7 +49,6 @@
#include "lib/tty/tty.h"
#include "lib/tty/key.h" /* For init_key() */
#include "lib/tty/mouse.h" /* init_mouse() */
#include "lib/timer.h"
#include "lib/skin.h"
#include "lib/filehighlight.h"
#include "lib/fileloc.h"
@ -255,8 +254,6 @@ main (int argc, char *argv[])
mc_global.run_from_parent_mc = !check_sid ();
mc_global.timer = mc_timer_new ();
/* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
#ifdef HAVE_SETLOCALE
(void) setlocale (LC_ALL, "");
@ -277,7 +274,6 @@ main (int argc, char *argv[])
startup_exit_ok:
mc_shell_deinit ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
return exit_code;
}
@ -557,8 +553,6 @@ main (int argc, char *argv[])
exit_code = EXIT_FAILURE;
}
mc_timer_destroy (mc_global.timer);
(void) putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
return exit_code;

View File

@ -43,7 +43,6 @@ 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 ();
@ -56,7 +55,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -79,7 +79,6 @@ config_object__deinit (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings ("KOI8-R");
vfs_init ();
vfs_init_localfs ();
@ -97,7 +96,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -59,7 +59,6 @@ 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 ();
@ -73,7 +72,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -45,7 +45,6 @@ static struct vfs_class vfs_test_ops;
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -74,7 +73,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -55,7 +55,6 @@ test_chdir (const vfs_path_t * vpath)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -75,7 +74,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -42,7 +42,6 @@
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -67,7 +66,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -42,7 +42,6 @@
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -67,7 +66,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -60,7 +60,6 @@ init_test_classes (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -87,7 +86,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -65,7 +65,6 @@ teardown (void)
static void
test_init_vfs (const char *encoding)
{
mc_global.timer = mc_timer_new ();
str_init_strings (encoding);
vfs_init ();
@ -86,7 +85,6 @@ test_deinit_vfs (void)
free_codepages_list ();
str_uninit_strings ();
vfs_shut ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -45,7 +45,6 @@ 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 ();
@ -79,7 +78,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -73,7 +73,6 @@ test_chdir__deinit (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -102,7 +101,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -45,7 +45,6 @@
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -61,7 +60,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -55,7 +55,6 @@ setup (void)
{
static struct stat initstat;
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -81,7 +80,6 @@ teardown (void)
vfs_s_free_entry (vfs_test_ops1, vfs_root_entry);
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -46,7 +46,6 @@ mc_config_get_home_dir (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -62,7 +61,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -48,7 +48,6 @@ 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 ();
@ -82,7 +81,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -55,7 +55,6 @@ 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 ();
@ -81,7 +80,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -82,7 +82,6 @@ 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 ();
@ -110,7 +109,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}

View File

@ -76,7 +76,6 @@ 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 ();
@ -92,7 +91,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -41,7 +41,6 @@ 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 ();
@ -66,7 +65,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -29,7 +29,6 @@
#include <ctype.h>
#include "lib/timer.h"
#ifdef HAVE_CHARSET
#include "lib/charsets.h"
#endif
@ -152,7 +151,6 @@ editcmd_dialog_completion_show__deinit (void)
static void
my_setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -187,7 +185,6 @@ my_teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -238,7 +238,6 @@ mc_ungetlocalcopy__deinit (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
vfs_init_localfs ();
@ -267,7 +266,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -95,7 +95,6 @@ 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 ();
@ -114,7 +113,6 @@ teardown (void)
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -80,7 +80,6 @@ mc_config_get_home_dir (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -98,7 +97,6 @@ teardown (void)
vfs_path_free (do_cd__new_dir_vpath__captured);
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -42,7 +42,6 @@
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -62,7 +61,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -38,7 +38,6 @@
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
str_init_strings (NULL);
vfs_init ();
@ -54,7 +53,6 @@ teardown (void)
{
vfs_shut ();
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -30,7 +30,6 @@
#include "lib/strutil.h"
#include "lib/util.h"
#include "lib/timer.h"
#include "src/filemanager/midnight.h"
@ -62,7 +61,6 @@ rand (void)
static void
setup (void)
{
mc_global.timer = mc_timer_new ();
mc_global.share_data_dir = (char *) TEST_SHARE_DIR;
str_init_strings (NULL);
}
@ -71,7 +69,6 @@ static void
teardown (void)
{
str_uninit_strings ();
mc_timer_destroy (mc_global.timer);
}
/* --------------------------------------------------------------------------------------------- */