summaryrefslogtreecommitdiff
path: root/riscos/schedule.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-03-08 14:13:27 +0000
committerVincent Sanders <vince@kyllikki.org>2014-03-09 15:37:40 +0000
commit87f6314dabdc2067a19e01f8b29f9ecc38ed825b (patch)
tree78f8f8395e3bf3b7ee2c18a7b5a5e6d2d5ca9ddc /riscos/schedule.c
parentfb9b171e325488dc9792ee0f3062f15d8ec597ee (diff)
downloadnetsurf-87f6314dabdc2067a19e01f8b29f9ecc38ed825b.tar.gz
netsurf-87f6314dabdc2067a19e01f8b29f9ecc38ed825b.tar.bz2
move scheduleing into browser operation table
Diffstat (limited to 'riscos/schedule.c')
-rw-r--r--riscos/schedule.c88
1 files changed, 43 insertions, 45 deletions
diff --git a/riscos/schedule.c b/riscos/schedule.c
index 257f2e72f..51290056d 100644
--- a/riscos/schedule.c
+++ b/riscos/schedule.c
@@ -24,10 +24,11 @@
#include <stdbool.h>
#include <stdlib.h>
+
#include "oslib/os.h"
-#include "riscos/gui.h"
#include "utils/log.h"
-#include "utils/schedule.h"
+
+#include "riscos/gui.h"
/** Entry in the queue of scheduled callbacks. */
@@ -50,25 +51,53 @@ bool sched_active = false;
/** Time of soonest scheduled event (valid only if sched_active is true). */
os_t sched_time;
-
/**
- * Schedule a callback.
+ * Unschedule a callback.
*
- * \param t interval before the callback should be made / cs
* \param callback callback function
* \param p user parameter, passed to callback function
*
- * The callback function will be called as soon as possible after t cs have
- * passed.
+ * All scheduled callbacks matching both callback and p are removed.
*/
-void schedule(int t, void (*callback)(void *p), void *p)
+static nserror schedule_remove(void (*callback)(void *p), void *p)
+{
+ struct sched_entry *entry, *next;
+
+ for (entry = &sched_queue; entry->next; entry = entry->next) {
+ if (entry->next->callback != callback || entry->next->p != p)
+ continue;
+ next = entry->next;
+ entry->next = entry->next->next;
+ free(next);
+ if (!entry->next)
+ break;
+ }
+
+ if (sched_queue.next) {
+ sched_active = true;
+ sched_time = sched_queue.next->time;
+ } else {
+ sched_active = false;
+ }
+
+ return NSERROR_OK;
+}
+
+/* exported function documented in riscos/gui.h */
+nserror riscos_schedule(int t, void (*callback)(void *p), void *p)
{
struct sched_entry *entry;
struct sched_entry *queue;
os_t time;
+ nserror ret;
- schedule_remove(callback, p);
+ ret = schedule_remove(callback, p);
+ if ((t < 0) || (ret != NSERROR_OK)) {
+ return ret;
+ }
+
+ t = t / 10; /* convert to centiseconds */
time = os_read_monotonic_time() + t;
@@ -91,44 +120,12 @@ void schedule(int t, void (*callback)(void *p), void *p)
sched_active = true;
sched_time = sched_queue.next->time;
-}
-
-/**
- * Unschedule a callback.
- *
- * \param callback callback function
- * \param p user parameter, passed to callback function
- *
- * All scheduled callbacks matching both callback and p are removed.
- */
-
-void schedule_remove(void (*callback)(void *p), void *p)
-{
- struct sched_entry *entry, *next;
-
- for (entry = &sched_queue; entry->next; entry = entry->next) {
- if (entry->next->callback != callback || entry->next->p != p)
- continue;
- next = entry->next;
- entry->next = entry->next->next;
- free(next);
- if (!entry->next)
- break;
- }
-
- if (sched_queue.next) {
- sched_active = true;
- sched_time = sched_queue.next->time;
- } else
- sched_active = false;
+ return NSERROR_OK;
}
-/**
- * Process events up to current time.
- */
-
+/* exported function documented in riscos/gui.h */
bool schedule_run(void)
{
struct sched_entry *entry;
@@ -144,8 +141,9 @@ bool schedule_run(void)
p = entry->p;
sched_queue.next = entry->next;
free(entry);
- /* The callback may call schedule() or schedule_remove(), so
- * leave the queue in a safe state. */
+ /* The callback may call riscos_schedule(), so leave
+ * the queue in a safe state.
+ */
callback(p);
}