schedule: return next thread pointer directly
authorBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 02:22:50 +0000 (18:22 -0800)
committerBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 02:22:50 +0000 (18:22 -0800)
It's better to just return a pointer to the 'next' thread, rather than
sending it through the argument list.

libthreads.c
schedule.c
schedule.h

index 2a4c51c1243cf8339aa7134b5d3c0c52ec0c9820..8bdd76ea153f58d585c767581635dbca75a711fc 100644 (file)
@@ -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));
 }
index a06a5c402f2f0ae13be90f263d87dce79a17c063..d567dd7fd5799f3723acf3d2ff678fa3471e6cea 100644 (file)
@@ -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();
 }
index 801af0d839c7beb274aaadc66c719f627f2713a7..ac69fa1163bfdfb3d8aff5a1f4ad249cdecb54e0 100644 (file)
@@ -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__ */