From: Brian Norris Date: Sat, 10 Mar 2012 02:22:50 +0000 (-0800) Subject: schedule: return next thread pointer directly X-Git-Tag: pldi2013~603 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=01237c41090e450db348ef0045a3d3cfd23cd041;p=model-checker.git schedule: return next thread pointer directly It's better to just return a pointer to the 'next' thread, rather than sending it through the argument list. --- diff --git a/libthreads.c b/libthreads.c index 2a4c51c..8bdd76e 100644 --- a/libthreads.c +++ b/libthreads.c @@ -61,7 +61,7 @@ static int thread_yield() 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); @@ -83,7 +83,7 @@ static void thread_wait_finish() do { if (current) thread_dispose(current); - schedule_choose_next(&next); + next = schedule_choose_next(); current = next; } while (next && !thread_swap(main_thread, next)); } diff --git a/schedule.c b/schedule.c index a06a5c4..d567dd7 100644 --- a/schedule.c +++ b/schedule.c @@ -32,18 +32,20 @@ static void enqueue_thread(struct thread *t) 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) @@ -52,7 +54,7 @@ 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(); } diff --git a/schedule.h b/schedule.h index 801af0d..ac69fa1 100644 --- a/schedule.h +++ b/schedule.h @@ -4,6 +4,6 @@ #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__ */