- time_t now, delta;
- struct sched *p, *next = NULL;
-
- if (slept_at || woke_at) {
- plog(LLV_DEBUG, LOCATION, NULL,
- "ignoring schedular until power-mgmt event is handled.\n");
- return NULL;
- }
-
- now = current_time();
-
- for (p = TAILQ_FIRST(&sctree); p; p = next) {
- /* if the entry has been dead, remove it */
- if (p->dead)
- goto next_schedule;
-
- /* if the time hasn't come, proceed to the next entry */
- if (now < p->xtime) {
- next = TAILQ_NEXT(p, chain);
- continue;
- }
-
- /* mark it with dead. and call the function. */
- p->dead = 1;
- if (p->func != NULL && !terminated)
- (p->func)(p->param);
-
- next_schedule:
- next = TAILQ_NEXT(p, chain);
- TAILQ_REMOVE(&sctree, p, chain);
- racoon_free(p);
- }
-
- p = TAILQ_FIRST(&sctree);
- if (p == NULL)
- return NULL;
-
- now = current_time();
-
- delta = p->xtime - now;
- timeout.tv_sec = delta < 0 ? 0 : delta;
- timeout.tv_usec = 0;
-
- return &timeout;
+ if (slept_at || woke_at)
+ sched->dead = 1;
+
+ TAILQ_REMOVE(&sctree, sched, chain);
+
+ if (!sched->dead) {
+ if (sched->func != NULL && !terminated) {
+ (sched->func)(sched->param);
+ }
+ }
+ racoon_free(sched);