Browse Source

Drop mc_timer. Use g_get_real_time() instead.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 4 years ago
parent
commit
78893d85b8
10 changed files with 13 additions and 156 deletions
  1. 1 2
      lib/Makefile.am
  2. 0 2
      lib/global.c
  3. 0 4
      lib/global.h
  4. 0 106
      lib/timer.c
  5. 0 27
      lib/timer.h
  6. 3 4
      lib/util.c
  7. 1 1
      lib/util.h
  8. 4 4
      lib/widget/wtools.c
  9. 2 4
      lib/widget/wtools.h
  10. 2 2
      src/filemanager/file.c

+ 1 - 2
lib/Makefile.am

@@ -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

+ 0 - 2
lib/global.c

@@ -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,

+ 0 - 4
lib/global.h

@@ -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;
 

+ 0 - 106
lib/timer.c

@@ -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);
-}
-
-/* --------------------------------------------------------------------------------------------- */

+ 0 - 27
lib/timer.h

@@ -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 */

+ 3 - 4
lib/util.c

@@ -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;

+ 1 - 1
lib/util.h

@@ -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 **************************************************/
 

+ 4 - 4
lib/widget/wtools.c

@@ -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);

+ 2 - 4
lib/widget/wtools.h

@@ -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 */

+ 2 - 2
src/filemanager/file.c

@@ -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;

Some files were not shown because too many files changed in this diff