summaryrefslogtreecommitdiff
path: root/framebuffer
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2010-04-28 22:39:37 +0000
committerVincent Sanders <vince@netsurf-browser.org>2010-04-28 22:39:37 +0000
commit2fd1476f8c99c4d4f6eb114cc7b5f8ac9ab54be4 (patch)
tree8379dd89d75de03107e8db044964dd40d49cbcfa /framebuffer
parent085f6b33ecbc5642c8c5fb9c6ec7612f5f9dcec3 (diff)
downloadnetsurf-2fd1476f8c99c4d4f6eb114cc7b5f8ac9ab54be4.tar.gz
netsurf-2fd1476f8c99c4d4f6eb114cc7b5f8ac9ab54be4.tar.bz2
The schedule_run function is only called by the frontends so remove it from the core header and add its definition to the frontend headers.
Alter the framebuffer schedule_run to return the time untill the next event. svn path=/trunk/netsurf/; revision=10512
Diffstat (limited to 'framebuffer')
-rw-r--r--framebuffer/gui.c14
-rw-r--r--framebuffer/schedule.c40
-rw-r--r--framebuffer/schedule.h1
3 files changed, 41 insertions, 14 deletions
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 7eae2b630..2689ffd8b 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -472,12 +472,18 @@ void gui_multitask(void)
void gui_poll(bool active)
{
nsfb_event_t event;
- int timeout = 0;
+ int timeout;
- active |= schedule_run() | redraws_pending;
+ /* run the scheduler and discover how long to wait for the next event */
+ timeout = schedule_run();
- if (!active)
- timeout = -1;
+ /* if active do not wait for event, return immediately */
+ if (active)
+ timeout = 0;
+
+ /* if redraws are pending do not wait for event, return immediately */
+ if (redraws_pending)
+ timeout = 0;
if (fbtk_event(fbtk, &event, timeout)) {
if ((event.type == NSFB_EVENT_CONTROL) &&
diff --git a/framebuffer/schedule.c b/framebuffer/schedule.c
index 986c8e909..150ac037b 100644
--- a/framebuffer/schedule.c
+++ b/framebuffer/schedule.c
@@ -123,21 +123,27 @@ void schedule_remove(void (*callback)(void *p), void *p)
}
/**
- * Process events up to current time.
+ * Process scheduled callbacks up to current time.
+ *
+ * @return The number of centiseconds untill the next callback or -1 for never.
*/
-
-bool schedule_run(void)
+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;
if (schedule_list == NULL)
- return false;
+ return -1;
+ /* reset enumeration to the start of the list */
cur_nscb = schedule_list;
prev_nscb = NULL;
+ nexttime = cur_nscb->tv;
gettimeofday(&tv, NULL);
@@ -159,21 +165,35 @@ bool schedule_run(void)
/* call callback */
unlnk_nscb->callback(unlnk_nscb->p);
- free (unlnk_nscb);
+ free(unlnk_nscb);
- /* the callback might have modded the list, so start
- * again
- */
+ /* need to deal with callback modifying the list. */
+ if (schedule_list == NULL)
+ return -1; /* no more callbacks scheduled */
+
+ /* reset enumeration to the start of the list */
cur_nscb = schedule_list;
prev_nscb = NULL;
-
+ nexttime = cur_nscb->tv;
} else {
+ /* 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;
}
}
- return true;
+
+ /* make rettime relative to now */
+ timersub(&nexttime, &tv, &rettime);
+
+ LOG(("returning time to next event as %ldcs",(rettime.tv_sec * 100) + (rettime.tv_usec / 10000)));
+ /* return next event time in cs */
+ return (rettime.tv_sec * 100) + (rettime.tv_usec / 10000);
}
void list_schedule(void)
diff --git a/framebuffer/schedule.h b/framebuffer/schedule.h
index f735a06df..2c9b55f82 100644
--- a/framebuffer/schedule.h
+++ b/framebuffer/schedule.h
@@ -19,6 +19,7 @@
#ifndef FRAMEBUFFER_SCHEDULE_H
#define FRAMEBUFFER_SCHEDULE_H
+int schedule_run(void);
void list_schedule(void);
#endif