raster pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=14e1583cd038d550d035d6965733f18f5ca9ae0f

commit 14e1583cd038d550d035d6965733f18f5ca9ae0f
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Tue Sep 12 09:08:04 2017 +0900

    Revert "Sysinfo gadgets: Revert all uses of faulty e_powersave_sleeper."
    
    This reverts commit f8e17b67e463850002c92e3ec9d16d557185bbbe.
---
 src/modules/sysinfo/cpuclock/cpuclock.c        |  5 ++++-
 src/modules/sysinfo/cpumonitor/cpumonitor.c    |  5 ++++-
 src/modules/sysinfo/memusage/memusage.c        |  5 ++++-
 src/modules/sysinfo/netstatus/netstatus.c      |  5 ++++-
 src/modules/sysinfo/netstatus/netstatus_proc.c | 10 +++++-----
 src/modules/sysinfo/sysinfo.h                  |  1 +
 src/modules/sysinfo/thermal/thermal.c          |  6 ++++--
 7 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/modules/sysinfo/cpuclock/cpuclock.c 
b/src/modules/sysinfo/cpuclock/cpuclock.c
index 8424b4cec..e786fe613 100644
--- a/src/modules/sysinfo/cpuclock/cpuclock.c
+++ b/src/modules/sysinfo/cpuclock/cpuclock.c
@@ -16,6 +16,7 @@ struct _Thread_Config
 {
    int                  interval;
    Instance            *inst;
+   E_Powersave_Sleeper *sleeper;
 };
 
 typedef struct _Pstate_Config Pstate_Config;
@@ -839,7 +840,7 @@ _cpuclock_cb_frequency_check_main(void *data, Ecore_Thread 
*th)
         else
           _cpuclock_status_free(status);
         if (ecore_thread_check(th)) break;
-        usleep((1000000.0 / 8.0) * (double)thc->interval);
+        e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -893,6 +894,7 @@ _cpuclock_cb_frequency_check_end(void *data, Ecore_Thread 
*th EINA_UNUSED)
 {
    Thread_Config *thc = data;
 
+   e_powersave_sleeper_free(thc->sleeper);
    E_FREE(thc);
 }
 
@@ -910,6 +912,7 @@ _cpuclock_poll_interval_update(Instance *inst)
    if (thc)
      {
         thc->inst = inst;
+        thc->sleeper = e_powersave_sleeper_new();
         thc->interval = inst->cfg->cpuclock.poll_interval;
         inst->cfg->cpuclock.frequency_check_thread =
           ecore_thread_feedback_run(_cpuclock_cb_frequency_check_main,
diff --git a/src/modules/sysinfo/cpumonitor/cpumonitor.c 
b/src/modules/sysinfo/cpumonitor/cpumonitor.c
index 83084bd40..3a2081faa 100644
--- a/src/modules/sysinfo/cpumonitor/cpumonitor.c
+++ b/src/modules/sysinfo/cpumonitor/cpumonitor.c
@@ -10,6 +10,7 @@ struct _Thread_Config
    unsigned long        total;
    unsigned long        idle;
    Instance            *inst;
+   E_Powersave_Sleeper *sleeper;
    Eina_List           *cores;
 };
 
@@ -172,7 +173,7 @@ _cpumonitor_cb_usage_check_main(void *data, Ecore_Thread 
*th)
 #endif
         ecore_thread_feedback(th, NULL);
         if (ecore_thread_check(th)) break;
-        usleep((1000000.0 / 8.0) * (double)thc->interval);
+        e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -196,6 +197,7 @@ _cpumonitor_cb_usage_check_end(void *data, Ecore_Thread *th 
EINA_UNUSED)
    Thread_Config *thc = data;
    CPU_Core *core;
 
+   e_powersave_sleeper_free(thc->sleeper);
    EINA_LIST_FREE(thc->cores, core)
      E_FREE(core);
    E_FREE(thc);
@@ -305,6 +307,7 @@ _cpumonitor_config_updated(Instance *inst)
         thc->idle = 0;
         thc->percent = 0;
         thc->interval = inst->cfg->cpumonitor.poll_interval;
+        thc->sleeper = e_powersave_sleeper_new();
 #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
         thc->num_cores = _cpumonitor_sysctl_getcores();
 #else
diff --git a/src/modules/sysinfo/memusage/memusage.c 
b/src/modules/sysinfo/memusage/memusage.c
index 42c1a6a7e..acb8545f6 100644
--- a/src/modules/sysinfo/memusage/memusage.c
+++ b/src/modules/sysinfo/memusage/memusage.c
@@ -15,6 +15,7 @@ struct _Thread_Config
    unsigned long        mem_shared;
    unsigned long        swp_total;
    unsigned long        swp_used;
+   E_Powersave_Sleeper *sleeper;
 };
 
 static void
@@ -293,7 +294,7 @@ _memusage_cb_usage_check_main(void *data, Ecore_Thread *th)
 
         ecore_thread_feedback(th, NULL);
         if (ecore_thread_check(th)) break;
-        usleep((1000000.0 / 8.0) * (double)thc->interval);
+        e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -302,6 +303,7 @@ static void
 _memusage_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
 {
    Thread_Config *thc = data;
+   e_powersave_sleeper_free(thc->sleeper);
    E_FREE(thc);
 }
 
@@ -372,6 +374,7 @@ _memusage_config_updated(Instance *inst)
    if (thc)
      {
         thc->inst = inst;
+        thc->sleeper = e_powersave_sleeper_new();
         thc->interval = inst->cfg->memusage.poll_interval;
         thc->mem_percent = 0;
         thc->swp_percent = 0;
diff --git a/src/modules/sysinfo/netstatus/netstatus.c 
b/src/modules/sysinfo/netstatus/netstatus.c
index 9119c416e..0e87854a7 100644
--- a/src/modules/sysinfo/netstatus/netstatus.c
+++ b/src/modules/sysinfo/netstatus/netstatus.c
@@ -19,6 +19,7 @@ struct _Thread_Config
    unsigned long        outcurrent;
    unsigned long        outmax;
    Eina_Stringshare    *outstring;
+   E_Powersave_Sleeper *sleeper;
 };
 
 static void
@@ -180,7 +181,7 @@ _netstatus_cb_usage_check_main(void *data, Ecore_Thread *th)
         eina_stringshare_replace(&thc->outstring, rout);
         ecore_thread_feedback(th, NULL);
         if (ecore_thread_check(th)) break;
-        usleep((1000000.0 / 8.0) * (double)thc->interval);
+        e_powersave_sleeper_sleep(thc->sleeper, thc->interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -204,6 +205,7 @@ static void
 _netstatus_cb_usage_check_end(void *data, Ecore_Thread *th EINA_UNUSED)
 {
    Thread_Config *thc = data;
+   e_powersave_sleeper_free(thc->sleeper);
    E_FREE_FUNC(thc->instring, eina_stringshare_del);
    E_FREE_FUNC(thc->outstring, eina_stringshare_del);
    E_FREE(thc);
@@ -259,6 +261,7 @@ _netstatus_config_updated(Instance *inst)
    if (thc)
      {
         thc->inst = inst;
+        thc->sleeper = e_powersave_sleeper_new();
         thc->interval = inst->cfg->netstatus.poll_interval;
         thc->in = 0;
         thc->inmax = inst->cfg->netstatus.inmax;
diff --git a/src/modules/sysinfo/netstatus/netstatus_proc.c 
b/src/modules/sysinfo/netstatus/netstatus_proc.c
index 56a8a4056..1659ce471 100644
--- a/src/modules/sysinfo/netstatus/netstatus_proc.c
+++ b/src/modules/sysinfo/netstatus/netstatus_proc.c
@@ -18,7 +18,7 @@ _netstatus_proc_getrstatus(Eina_Bool automax,
 
    if (!*last_checked)
      *last_checked = current;
-   if ((current - *last_checked) < 1)
+   else if ((current - *last_checked) < 1)
      return;
    else
      diff = current - *last_checked;
@@ -73,15 +73,15 @@ _netstatus_proc_gettstatus(Eina_Bool automax,
    int percent = 0;
    char buf[4096], dummys[64];
    FILE *f;
-   time_t last = *last_checked, current = time(NULL);
+   time_t current = time(NULL);
    time_t diff = 0;
 
-   if (!last)
+   if (!*last_checked)
      *last_checked = current;
-   else if ((current - last) < 1)
+   else if ((current - *last_checked) < 1)
      return;
    else
-     diff = current - last;
+     diff = current - *last_checked;
    f = fopen("/proc/net/dev", "r");
    if (f)
      {
diff --git a/src/modules/sysinfo/sysinfo.h b/src/modules/sysinfo/sysinfo.h
index 9f5f9cd0b..98b4c5a52 100644
--- a/src/modules/sysinfo/sysinfo.h
+++ b/src/modules/sysinfo/sysinfo.h
@@ -76,6 +76,7 @@ struct _Tempthread
    const char *sensor_name;
    const char *sensor_path;
    void *extn;
+   E_Powersave_Sleeper *sleeper;
 #if defined(HAVE_EEZE)
    Eina_List *tempdevs;
 #endif
diff --git a/src/modules/sysinfo/thermal/thermal.c 
b/src/modules/sysinfo/thermal/thermal.c
index b34da4a53..f09d05322 100644
--- a/src/modules/sysinfo/thermal/thermal.c
+++ b/src/modules/sysinfo/thermal/thermal.c
@@ -14,6 +14,7 @@ _thermal_thread_free(Tempthread *tth)
    EINA_LIST_FREE(tth->tempdevs, s)
      eina_stringshare_del(s);
 #endif
+   e_powersave_sleeper_free(tth->sleeper);
    E_FREE(tth->extn);
    E_FREE(tth);
 }
@@ -98,7 +99,7 @@ _thermal_check_sysctl(void *data, Ecore_Thread *th)
         temp = thermal_sysctl_get(tth);
         if (ptemp != temp) ecore_thread_feedback(th, (void *)((long)temp));
         ptemp = temp;
-        usleep((1000000.0 / 8.0) * (double)thc->poll_interval);
+        e_powersave_sleeper_sleep(tth->sleeper, tth->poll_interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -117,7 +118,7 @@ _thermal_check_fallback(void *data, Ecore_Thread *th)
         temp = thermal_fallback_get(tth);
         if (ptemp != temp) ecore_thread_feedback(th, (void *)((long)temp));
         ptemp = temp;
-        usleep((1000000.0 / 8.0) * (double)thc->poll_interval);
+        e_powersave_sleeper_sleep(tth->sleeper, tth->poll_interval);
         if (ecore_thread_check(th)) break;
      }
 }
@@ -273,6 +274,7 @@ _thermal_config_updated(Instance *inst)
    tth->poll_interval = inst->cfg->thermal.poll_interval;
    tth->sensor_type = inst->cfg->thermal.sensor_type;
    tth->inst = inst;
+   tth->sleeper = e_powersave_sleeper_new();
    if (inst->cfg->thermal.sensor_name)
      tth->sensor_name = eina_stringshare_add(inst->cfg->thermal.sensor_name);
 

-- 


Reply via email to