summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshish Gupta <ashmew2@gmail.com>2017-09-21 22:28:30 (GMT)
committer Ashish Gupta <ashmew2@gmail.com>2017-09-21 23:02:54 (GMT)
commit72191e346bfd621d217e310f8865efdb34ce4fa3 (patch)
tree028650aae2f5b709f36877d790a2f7dc32f9da25
parent8393ebde2b166e96269462459e9639fa76d33719 (diff)
downloadnetsurf-72191e346bfd621d217e310f8865efdb34ce4fa3.tar.gz
netsurf-72191e346bfd621d217e310f8865efdb34ce4fa3.tar.bz2
Fix polling
-rw-r--r--frontends/kolibrios/fb/schedule.c121
-rw-r--r--utils/log.c16
2 files changed, 45 insertions, 92 deletions
diff --git a/frontends/kolibrios/fb/schedule.c b/frontends/kolibrios/fb/schedule.c
index 703c14d..044899a 100644
--- a/frontends/kolibrios/fb/schedule.c
+++ b/frontends/kolibrios/fb/schedule.c
@@ -15,41 +15,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#if defined(_TARGET_IS_KOLIBRIOS)
-
-#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
-#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
-#define timercmp(tvp, uvp, cmp) \
- (((tvp)->tv_sec == (uvp)->tv_sec) ? \
- ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
- ((tvp)->tv_sec cmp (uvp)->tv_sec))
-#define timeradd(tvp, uvp, vvp) \
- do { \
- (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
- (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
- if ((vvp)->tv_usec >= 1000000) { \
- (vvp)->tv_sec++; \
- (vvp)->tv_usec -= 1000000; \
- } \
- } while (0)
-#define timersub(tvp, uvp, vvp) \
- do { \
- (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
- (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
- if ((vvp)->tv_usec < 0) { \
- (vvp)->tv_sec--; \
- (vvp)->tv_usec += 1000000; \
- } \
- } while (0)
-
-#endif
#include <time.h>
#include <stdlib.h>
#include "utils/sys_time.h"
#include "utils/log.h"
-
+#include <kos32sys.h>
#include "kolibrios/fb/schedule.h"
#ifdef DEBUG_SCHEDULER
@@ -67,9 +39,9 @@ static struct nscallback *schedule_list = NULL;
struct nscallback
{
struct nscallback *next;
- struct timeval tv;
- void (*callback)(void *p);
- void *p;
+ uint32_t tv;
+ void (*callback)(void *p);
+ void *p;
};
/**
@@ -128,7 +100,6 @@ static nserror schedule_remove(void (*callback)(void *p), void *p)
nserror framebuffer_schedule(int tival, void (*callback)(void *p), void *p)
{
struct nscallback *nscb;
- struct timeval tv;
nserror ret;
/* ensure uniqueness of the callback and context */
@@ -137,22 +108,16 @@ nserror framebuffer_schedule(int tival, void (*callback)(void *p), void *p)
return ret;
}
- SRLOG("Adding %p(%p) in %d", callback, p, tival);
-
- tv.tv_sec = tival / 1000; /* miliseconds to seconds */
- tv.tv_usec = (tival % 1000) * 1000; /* remainder to microseconds */
+ LOG("Adding %p(%p) in %d", callback, p, tival);
nscb = calloc(1, sizeof(struct nscallback));
-
- gettimeofday(&nscb->tv, NULL);
- timeradd(&nscb->tv, &tv, &nscb->tv);
-
+ nscb->tv = get_tick_count() + tival / 10;
nscb->callback = callback;
nscb->p = p;
- /* add to list front */
- nscb->next = schedule_list;
- schedule_list = nscb;
+ /* add to list front */
+ nscb->next = schedule_list;
+ schedule_list = nscb;
return NSERROR_OK;
}
@@ -160,26 +125,26 @@ nserror framebuffer_schedule(int tival, void (*callback)(void *p), void *p)
/* exported function documented in framebuffer/schedule.h */
int schedule_run(void)
{
- struct timeval tv;
- struct timeval nexttime;
- struct timeval rettime;
- struct nscallback *cur_nscb;
- struct nscallback *prev_nscb;
- struct nscallback *unlnk_nscb;
+ uint32_t tv;
+ uint32_t nexttime;
+ uint32_t rettime;
+ struct nscallback *cur_nscb;
+ struct nscallback *prev_nscb;
+ struct nscallback *unlnk_nscb;
- if (schedule_list == NULL)
- return -1;
+ if (schedule_list == NULL)
+ return -1;
/* reset enumeration to the start of the list */
- cur_nscb = schedule_list;
- prev_nscb = NULL;
+ cur_nscb = schedule_list;
+ prev_nscb = NULL;
nexttime = cur_nscb->tv;
- gettimeofday(&tv, NULL);
+ tv = get_tick_count();
- while (cur_nscb != NULL) {
- if (timercmp(&tv, &cur_nscb->tv, >)) {
- /* scheduled time */
+ while (cur_nscb != NULL) {
+ if (tv > cur_nscb->tv) {
+ /* scheduled time */
/* remove callback */
unlnk_nscb = cur_nscb;
@@ -206,39 +171,39 @@ int schedule_run(void)
/* if the time to the event is sooner than the
* currently recorded soonest event record it
*/
- if (timercmp(&nexttime, &cur_nscb->tv, >)) {
- nexttime = cur_nscb->tv;
- }
- /* move to next element */
- prev_nscb = cur_nscb;
- cur_nscb = prev_nscb->next;
- }
- }
+ if (nexttime > cur_nscb->tv) {
+ nexttime = cur_nscb->tv;
+ }
+ /* move to next element */
+ prev_nscb = cur_nscb;
+ cur_nscb = prev_nscb->next;
+ }
+ }
/* make rettime relative to now */
- timersub(&nexttime, &tv, &rettime);
+ rettime = tv - nexttime;
- SRLOG("returning time to next event as %ldms",(rettime.tv_sec * 1000) + (rettime.tv_usec / 1000));
+ /* SRLOG("returning time to next event as %ldms",(rettime.tv_sec * 1000) + (rettime.tv_usec / 1000)); */
/* return next event time in milliseconds (24days max wait) */
- return (rettime.tv_sec * 1000) + (rettime.tv_usec / 1000);
+ return rettime * 10;
}
void list_schedule(void)
{
- struct timeval tv;
- struct nscallback *cur_nscb;
+ uint32_t tv;
+ struct nscallback *cur_nscb;
- gettimeofday(&tv, NULL);
+ tv = get_tick_count();
- LOG("schedule list at %ld:%ld", tv.tv_sec, tv.tv_usec);
+ LOG("schedule list at %u", tv);
- cur_nscb = schedule_list;
+ cur_nscb = schedule_list;
- while (cur_nscb != NULL) {
- LOG("Schedule %p at %ld:%ld", cur_nscb, cur_nscb->tv.tv_sec, cur_nscb->tv.tv_usec);
- cur_nscb = cur_nscb->next;
- }
+ while (cur_nscb != NULL) {
+ LOG("Schedule %p at %ld", cur_nscb, cur_nscb->tv);
+ cur_nscb = cur_nscb->next;
+ }
}
diff --git a/utils/log.c b/utils/log.c
index 45cc210..eb7bb9a 100644
--- a/utils/log.c
+++ b/utils/log.c
@@ -19,6 +19,7 @@
#include <stdarg.h>
#include <stdio.h>
+#include <kos32sys.h>
#include "utils/config.h"
#include "utils/nsoption.h"
#include "utils/sys_time.h"
@@ -71,21 +72,8 @@ timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
*/
static const char *nslog_gettime(void)
{
- static struct timeval start_tv;
static char buff[32];
-
- struct timeval tv;
- struct timeval now_tv;
-
- if (!timerisset(&start_tv)) {
- gettimeofday(&start_tv, NULL);
- }
- gettimeofday(&now_tv, NULL);
-
- timeval_subtract(&tv, &now_tv, &start_tv);
-
- snprintf(buff, sizeof(buff),"(%ld.%06ld)",
- (long)tv.tv_sec, (long)tv.tv_usec);
+ snprintf(buff, sizeof(buff),"(%u)", get_tick_count());
return buff;
}