libthreads: merge thread_create() and thread_start()
authorBrian Norris <banorris@uci.edu>
Fri, 9 Mar 2012 23:18:07 +0000 (15:18 -0800)
committerBrian Norris <banorris@uci.edu>
Fri, 9 Mar 2012 23:18:07 +0000 (15:18 -0800)
libthreads.c
libthreads.h

index c69e45ac609497e8d049a338a2edf4f85ec5e191..bd7f501df3cc4c76a1d7bb30c982f66df802cc1e 100644 (file)
@@ -86,6 +86,7 @@ static int master_thread_yield()
 int thread_create(struct thread *t, void (*start_routine), void *arg)
 {
        static int created = 1;
+       int ret = 0;
 
        DBG();
 
@@ -97,14 +98,12 @@ int thread_create(struct thread *t, void (*start_routine), void *arg)
        t->arg = arg;
 
        /* Initialize state */
-       return create_context(t);
-}
-
-void thread_start(struct thread *t)
-{
-       DBG();
+       ret = create_context(t);
+       if (ret)
+               return ret;
 
        schedule_add_thread(t);
+       return 0;
 }
 
 void thread_join(struct thread *t)
@@ -129,13 +128,10 @@ void user_main()
        struct thread t1, t2;
        int i = 2, j = 3;
 
+       printf("%s() creating 2 threads\n", __func__);
        thread_create(&t1, &a, &i);
        thread_create(&t2, &a, &j);
 
-       printf("%s() is going to start 1 thread\n", __func__);
-       thread_start(&t1);
-       thread_start(&t2);
-
        thread_join(&t1);
        thread_join(&t2);
        printf("%s() is finished\n", __func__);
@@ -149,7 +145,6 @@ int main()
        create_initial_thread(main_thread);
 
        thread_create(&user_thread, &user_main, NULL);
-       thread_start(&user_thread);
 
        /* Wait for all threads to complete */
        while (master_thread_yield() == 0);
index ff6d5aa975770cd1d5780e3c24ecc1a2db1ab51d..f8a86cdfb5f24e2c42c28955fcc52a8dd2351cb2 100644 (file)
@@ -22,6 +22,5 @@ struct thread {
 };
 
 int thread_create(struct thread *t, void (*start_routine), void *arg);
-void thread_start(struct thread *t);
 
 #endif /* __LIBTHREADS_H__ */