From 403e39f5a4bd3f8a2ed0e4d34c68a2ea2072ba17 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 9 Jul 2004 10:58:45 +0000 Subject: [project @ 2004-07-09 10:58:45 by bursa] Fix race condition in schedule_run() (fixes download-related crashes). svn path=/import/netsurf/; revision=1062 --- riscos/schedule.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'riscos/schedule.c') diff --git a/riscos/schedule.c b/riscos/schedule.c index 52e5e2660..c055c219f 100644 --- a/riscos/schedule.c +++ b/riscos/schedule.c @@ -118,15 +118,21 @@ void schedule_remove(void (*callback)(void *p), void *p) void schedule_run(void) { struct sched_entry *entry; + void (*callback)(void *p); + void *p; 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); + callback = entry->callback; + 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. */ + callback(p); } if (sched_queue.next) { -- cgit v1.2.3