summaryrefslogtreecommitdiff
path: root/amiga
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2014-07-02 18:35:16 +0100
committerChris Young <chris@unsatisfactorysoftware.co.uk>2014-07-02 18:35:16 +0100
commit5105249bf7aa91fc84fd53af06cc073ff7987168 (patch)
tree36c8e1daf1baede889eb450ba5659f72a7fc8f78 /amiga
parenta71865b328b721dcba49696f942335ec2baddc0f (diff)
downloadnetsurf-5105249bf7aa91fc84fd53af06cc073ff7987168.tar.gz
netsurf-5105249bf7aa91fc84fd53af06cc073ff7987168.tar.bz2
tidy up schedule removal
Diffstat (limited to 'amiga')
-rwxr-xr-xamiga/schedule.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/amiga/schedule.c b/amiga/schedule.c
index 9aa74881f..d0a0570dd 100755
--- a/amiga/schedule.c
+++ b/amiga/schedule.c
@@ -53,6 +53,32 @@ static void ami_remove_timer_event(struct nscallback *nscb)
}
}
+static struct nscallback *ami_schedule_locate(void (*callback)(void *p), void *p, bool remove)
+{
+ PblIterator *iterator;
+ struct nscallback *nscb;
+ bool found_cb = false;
+
+ /* check there is something on the list */
+ if (schedule_list == NULL) return NULL;
+ if(pblHeapIsEmpty(schedule_list)) return NULL;
+
+ iterator = pblHeapIterator(schedule_list);
+
+ while ((nscb = pblIteratorNext(iterator)) != -1) {
+ if ((nscb->callback == callback) && (nscb->p == p)) {
+ if (remove == true) pblIteratorRemove(iterator);
+ found_cb = true;
+ break;
+ }
+ };
+
+ pblIteratorFree(iterator);
+
+ if (found_cb == true) return nscb;
+ else return NULL;
+}
+
/**
* Unschedule a callback.
*
@@ -66,36 +92,12 @@ static nserror schedule_remove(void (*callback)(void *p), void *p)
{
PblIterator *iterator;
struct nscallback *nscb;
- bool restoreheap = false;
-
- /* check there is something on the list to remove */
- if (schedule_list == NULL)
- {
- return NSERROR_OK;
- }
-
- if(pblHeapIsEmpty(schedule_list))
- {
- return NSERROR_OK;
- }
-
- iterator = pblHeapIterator(schedule_list);
-
- while ((nscb = pblIteratorNext(iterator)) != -1)
- {
- if((nscb->callback == callback) && (nscb->p == p))
- {
- ami_remove_timer_event(nscb);
- pblIteratorRemove(iterator);
- FreeVec(nscb);
- restoreheap = true;
- }
- };
- pblIteratorFree(iterator);
+ nscb = ami_schedule_locate(callback, p, true);
- if(restoreheap)
- {
+ if(nscb != NULL) {
+ ami_remove_timer_event(nscb);
+ FreeVec(nscb);
pblHeapConstruct(schedule_list);
}
@@ -257,3 +259,4 @@ nserror ami_schedule(int t, void (*callback)(void *p), void *p)
return NSERROR_OK;
}
+