summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile2
-rw-r--r--riscos/gui.c3
-rw-r--r--riscos/gui.h7
-rw-r--r--riscos/schedule.c135
4 files changed, 146 insertions, 1 deletions
diff --git a/makefile b/makefile
index 54b68e8db..25c6b4cff 100644
--- a/makefile
+++ b/makefile
@@ -19,7 +19,7 @@ OBJECTS = $(OBJECTS_COMMON) \
draw.o gif.o jpeg.o plugin.o png.o sprite.o \
about.o filetype.o font.o uri.o url_protocol.o history.o \
version.o thumbnail.o \
- save.o save_complete.o save_draw.o
+ save.o save_complete.o save_draw.o schedule.o
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
netsurfd.o \
options.o filetyped.o fontd.o
diff --git a/riscos/gui.c b/riscos/gui.c
index f35f90832..7f9631f68 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -306,6 +306,8 @@ void gui_poll(bool active)
xhourglass_off();
if (active) {
event = wimp_poll(mask, &block, 0);
+ } else if (sched_active) {
+ event = wimp_poll_idle(mask, &block, sched_time, 0);
} else if (over_window || gui_reformat_pending) {
os_t t = os_read_monotonic_time();
event = wimp_poll_idle(mask, &block, t + 10, 0);
@@ -314,6 +316,7 @@ void gui_poll(bool active)
}
xhourglass_on();
ro_gui_handle_event(event, &block);
+ schedule_run();
if (gui_reformat_pending && event == wimp_NULL_REASON_CODE) {
for (g = window_list; g; g = g->next) {
diff --git a/riscos/gui.h b/riscos/gui.h
index 081040b2e..a0f7c6a19 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -162,6 +162,13 @@ void ro_gui_save_datasave_ack(wimp_message *message);
/* in filetype.c */
int ro_content_filetype(struct content *content);
+/* in schedule.c */
+extern bool sched_active;
+extern os_t sched_time;
+void schedule(int t, void (*callback)(void *p), void *p);
+void schedule_remove(void (*callback)(void *p), void *p);
+void schedule_run(void);
+
/* icon numbers */
#define ICON_TOOLBAR_THROBBER 1
#define ICON_TOOLBAR_URL 2
diff --git a/riscos/schedule.c b/riscos/schedule.c
new file mode 100644
index 000000000..a33b45ed6
--- /dev/null
+++ b/riscos/schedule.c
@@ -0,0 +1,135 @@
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
+ */
+
+/** \file
+ * Scheduled callback queue (implementation).
+ *
+ * The queue is simply implemented as a linked list.
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include "oslib/os.h"
+#include "netsurf/riscos/gui.h"
+#include "netsurf/utils/log.h"
+
+
+/** Entry in the queue of scheduled callbacks. */
+struct sched_entry {
+ /** Preferred time for callback. */
+ os_t time;
+ /** Function to call at the specified time. */
+ void (*callback)(void *p);
+ /** User parameter for callback. */
+ void *p;
+ /** Next (later) entry in queue. */
+ struct sched_entry *next;
+};
+
+/** Queue of scheduled callbacks (sentinel at head). */
+static struct sched_entry sched_queue = { 0, 0, 0, 0 };
+
+/** Items have been scheduled. */
+bool sched_active = false;
+/** Time of soonest scheduled event (valid only if sched_active is true). */
+os_t sched_time;
+
+
+/**
+ * Schedule 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.
+ */
+
+void schedule(int t, void (*callback)(void *p), void *p)
+{
+ struct sched_entry *entry;
+ struct sched_entry *queue;
+ os_t time;
+
+ time = os_read_monotonic_time() + t;
+
+ entry = malloc(sizeof *entry);
+ if (!entry) {
+ LOG(("malloc failed"));
+ return;
+ }
+
+ entry->time = time;
+ entry->callback = callback;
+ entry->p = p;
+
+ for (queue = &sched_queue;
+ queue->next && queue->next->time <= time;
+ queue = queue->next)
+ ;
+ entry->next = queue->next;
+ queue->next = entry;
+
+ 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 (sched_queue.next) {
+ sched_active = true;
+ sched_time = sched_queue.next->time;
+ } else
+ sched_active = false;
+}
+
+
+/**
+ * Process events up to current time.
+ */
+
+void schedule_run(void)
+{
+ struct sched_entry *entry;
+ os_t now;
+
+ now = os_read_monotonic_time();
+
+ while (sched_queue.next && sched_queue.next->time <= now) {
+ entry = sched_queue.next;
+ entry->callback(entry->p);
+ sched_queue.next = entry->next;
+ free(entry);
+ }
+
+ if (sched_queue.next) {
+ sched_active = true;
+ sched_time = sched_queue.next->time;
+ } else
+ sched_active = false;
+}