It's better to just return a pointer to the 'next' thread, rather than
sending it through the argument list.
DBG();
old = current;
schedule_add_thread(old);
- schedule_choose_next(&next);
+ next = schedule_choose_next();
current = next;
DEBUG("(%d, %d)\n", old->index, next->index);
return thread_swap(old, next);
do {
if (current)
thread_dispose(current);
- schedule_choose_next(&next);
+ next = schedule_choose_next();
current = next;
} while (next && !thread_swap(main_thread, next));
}
tail = node;
}
-static int dequeue_thread(struct thread **t)
+struct thread *dequeue_thread(void)
{
- if (!head) {
- *t = NULL;
- return -1;
- }
- *t = head->this;
+ struct thread *pop;
+
+ if (!head)
+ return NULL;
+
+ pop = head->this;
head->live = 0;
if (head == tail)
tail = NULL;
head = head->next;
- return 0;
+
+ return pop;
}
void schedule_add_thread(struct thread *t)
enqueue_thread(t);
}
-int schedule_choose_next(struct thread **t)
+struct thread *schedule_choose_next(void)
{
- return dequeue_thread(t);
+ return dequeue_thread();
}
#include "libthreads.h"
void schedule_add_thread(struct thread *t);
-int schedule_choose_next(struct thread **t);
+struct thread *schedule_choose_next(void);
#endif /* __SCHEDULE_H__ */