Re: [PATCH spice-gtk] file-xfer: Simplify time handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

On Tue, Aug 25, 2015 at 07:05:37PM +0200, Pavel Grunt wrote:
> Use g_get_monotonic_time() instead of g_date_time_new_now_local().
> g_get_monotonic_time doesn't suffer discontinuities and it is sufficient
> for our purposes. There is no need for the complexity of GDateTime.

Patch looks good!
  toso

> ---
>  src/channel-main.c | 26 +++++++++-----------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/src/channel-main.c b/src/channel-main.c
> index f5115aa..91e57b1 100644
> --- a/src/channel-main.c
> +++ b/src/channel-main.c
> @@ -71,8 +71,8 @@ typedef struct SpiceFileXferTask {
>      char                           buffer[FILE_XFER_CHUNK_SIZE];
>      uint64_t                       read_bytes;
>      uint64_t                       file_size;
> -    GDateTime                      *start_time;
> -    GDateTime                      *last_update;
> +    gint64                         start_time;
> +    gint64                         last_update;
>      GError                         *error;
>  } SpiceFileXferTask;
>  
> @@ -1697,10 +1697,6 @@ static void file_xfer_task_free(SpiceFileXferTask *task)
>      g_clear_object(&task->channel);
>      g_clear_object(&task->file);
>      g_clear_object(&task->file_stream);
> -    if (spice_util_get_debug()) {
> -        g_date_time_unref(task->start_time);
> -        g_date_time_unref(task->last_update);
> -    }
>      g_free(task);
>  }
>  
> @@ -1737,10 +1733,9 @@ static void file_xfer_close_cb(GObject      *object,
>      } else {
>          g_simple_async_result_set_op_res_gboolean(res, TRUE);
>          if (spice_util_get_debug()) {
> -            GDateTime *now = g_date_time_new_now_local();
> +            gint64 now = g_get_monotonic_time();
>              gchar *basename = g_file_get_basename(task->file);
> -            double seconds =
> -                (double) g_date_time_difference(now, task->start_time) / G_TIME_SPAN_SECOND;
> +            double seconds = (double) (now - task->start_time) / G_TIME_SPAN_SECOND;
>              gchar *file_size_str = g_format_size(task->file_size);
>              gchar *transfer_speed_str = g_format_size(task->file_size / seconds);
>  
> @@ -1751,7 +1746,6 @@ static void file_xfer_close_cb(GObject      *object,
>              g_free(basename);
>              g_free(file_size_str);
>              g_free(transfer_speed_str);
> -            g_date_time_unref(now);
>          }
>      }
>      g_simple_async_result_complete_in_idle(res);
> @@ -1777,17 +1771,15 @@ static void file_xfer_data_flushed_cb(GObject *source_object,
>  
>      if (spice_util_get_debug()) {
>          const GTimeSpan interval = 20 * G_TIME_SPAN_SECOND;
> -        GDateTime *now = g_date_time_new_now_local();
> +        gint64 now = g_get_monotonic_time();
>  
> -        if (interval < g_date_time_difference(now, task->last_update)) {
> +        if (interval < now - task->last_update) {
>              gchar *basename = g_file_get_basename(task->file);
> -            g_date_time_unref(task->last_update);
> -            task->last_update = g_date_time_ref(now);
> +            task->last_update = now;
>              SPICE_DEBUG("transferred %.2f%% of the file %s",
>                          100.0 * task->read_bytes / task->file_size, basename);
>              g_free(basename);
>          }
> -        g_date_time_unref(now);
>      }
>  
>      if (task->progress_callback)
> @@ -2956,8 +2948,8 @@ static void file_xfer_send_start_msg_async(SpiceMainChannel *channel,
>  
>          if (spice_util_get_debug()) {
>              gchar *basename = g_file_get_basename(task->file);
> -            task->start_time = g_date_time_new_now_local();
> -            task->last_update = g_date_time_ref(task->start_time);
> +            task->start_time = g_get_monotonic_time();
> +            task->last_update = task->start_time;
>  
>              SPICE_DEBUG("transfer of file %s has started", basename);
>              g_free(basename);
> -- 
> 2.5.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]