Updating branch refs/heads/master
         to 6b8162b4e9bf932bf7658f96de0a728b492e0b54 (commit)
       from d212ce6b437e954c3157f41305016117cbf9ea63 (commit)

commit 6b8162b4e9bf932bf7658f96de0a728b492e0b54
Author: Mike Massonnet <mmasson...@xfce.org>
Date:   Fri May 21 15:29:45 2010 +0200

    [linux|freebsd] Fix condition to calculate CPU usage

 src/task-manager-freebsd.c |    8 ++++++--
 src/task-manager-linux.c   |    8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c
index 2f69fc8..7db4549 100644
--- a/src/task-manager-freebsd.c
+++ b/src/task-manager-freebsd.c
@@ -87,8 +87,12 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat 
*cpu_system)
                cp_system = cpu_state[CP_SYS] + cpu_state[CP_INTR];
                cp_total = cpu_state[CP_IDLE] + cp_user + cp_system;
 
-               *cpu_user = (cp_user > cp_user_old) ? (cp_user - cp_user_old) * 
100 / (gdouble)(cp_total - cp_total_old) : 0;
-               *cpu_system = (cp_system > cp_system_old) ? (cp_system - 
cp_system_old) * 100 / (gdouble)(cp_total - cp_total_old) : 0;
+               *cpu_user = *cpu_system = 0.0;
+               if (cp_total > cp_total_old)
+               {
+                       *cpu_user = (cp_user - cp_user_old) * 100 / 
(gdouble)(cp_total - cp_total_old);
+                       *cpu_system = (cp_system - cp_system_old) * 100 / 
(gdouble)(cp_total - cp_total_old);
+               }
        }
 
        return TRUE;
diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index ba92f2e..e20356b 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -93,8 +93,12 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat 
*cpu_system)
        cur_jiffies_system = system;
        cur_jiffies = cur_jiffies_user + cur_jiffies_system + idle;
 
-       *cpu_user = (old_jiffies > 0) ? (cur_jiffies_user - old_jiffies_user) * 
100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
-       *cpu_system = (old_jiffies > 0) ? (cur_jiffies_system - 
old_jiffies_system) * 100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
+       *cpu_user = *cpu_system = 0.0;
+       if (cur_jiffies > old_jiffies)
+       {
+               *cpu_user = (cur_jiffies_user - old_jiffies_user) * 100 / 
(gdouble)(cur_jiffies - old_jiffies);
+               *cpu_system = (cur_jiffies_system - old_jiffies_system) * 100 / 
(gdouble)(cur_jiffies - old_jiffies);
+       }
        *cpu_count = _cpu_count;
 
        return TRUE;
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to