[Xfce4-commits] <thunar:shared-progress-dialog> Reduce the 'percent' signal emission frequency in ThunarTransferJob.
Jannis Pohlmann
jannis at xfce.org
Sat Sep 12 18:18:01 CEST 2009
Updating branch refs/heads/shared-progress-dialog
to 7d8ee42813b2b215b84ff40236c66697257332d2 (commit)
from 1fca6edc38868a1636214e41d1e6e65638bb8581 (commit)
commit 7d8ee42813b2b215b84ff40236c66697257332d2
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Sat Sep 12 18:10:58 2009 +0200
Reduce the 'percent' signal emission frequency in ThunarTransferJob.
GIO generates a lot of calls to the progress callback. If we simply
forward those to the GUI in the form of 'percent' signals, we cause the
CPU usage of the X server to go up dramatically (up to around 50%).
A better solution is to only emit the 'percent' signal from time to
time but frequently enough for progress bars to advance smoothly. This
is what this commit changes. From now on 'percent' is only emitted when
the percentage has increased by more than 0.05 percent since the
previous emission.
thunar/thunar-transfer-job.c | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c
index 7dc187d..78751b2 100644
--- a/thunar/thunar-transfer-job.c
+++ b/thunar/thunar-transfer-job.c
@@ -61,6 +61,8 @@ struct _ThunarTransferJob
guint64 total_size;
guint64 total_progress;
guint64 file_progress;
+
+ gdouble previous_percentage;
};
struct _ThunarTransferNode
@@ -100,6 +102,7 @@ thunar_transfer_job_init (ThunarTransferJob *job)
job->total_size = 0;
job->total_progress = 0;
job->file_progress = 0;
+ job->previous_percentage = 0.0;
}
@@ -124,6 +127,8 @@ thunar_transfer_job_progress (goffset current_num_bytes,
goffset total_num_bytes,
gpointer user_data)
{
+ guint64 new_percentage;
+
ThunarTransferJob *job = user_data;
_thunar_return_if_fail (THUNAR_IS_TRANSFER_JOB (job));
@@ -136,8 +141,19 @@ thunar_transfer_job_progress (goffset current_num_bytes,
/* update file progress */
job->file_progress = current_num_bytes;
- /* notify callers about the progress we made */
- exo_job_percent (EXO_JOB (job), (job->total_progress * 100.0) / job->total_size);
+ /* compute the new percentage after the progress we've made */
+ new_percentage = (job->total_progress * 100.0) / job->total_size;
+
+ /* notify callers about the progress only if we have advanced by
+ * at least 0.05 percent since the last signal emission */
+ if (new_percentage > (job->previous_percentage + 0.05))
+ {
+ /* emit the percent signal */
+ exo_job_percent (EXO_JOB (job), new_percentage);
+
+ /* remember the percentage */
+ job->previous_percentage = new_percentage;
+ }
}
}
More information about the Xfce4-commits
mailing list