Move position of blocking state in semaphore impl
authorKevin Klues <klueska@cs.berkeley.edu>
Tue, 18 Dec 2012 08:32:44 +0000 (00:32 -0800)
committerKevin Klues <klueska@cs.berkeley.edu>
Tue, 18 Dec 2012 08:32:44 +0000 (00:32 -0800)
user/pthread/semaphore.c

index f455595..54692e0 100644 (file)
@@ -40,7 +40,8 @@ int sem_unlink (__const char *__name)
 
 static void __sem_block(struct uthread *uthread, void *arg) {
        sem_t *__sem = (sem_t*)arg;
-    pthread_t pthread = (pthread_t)uthread;
+       pthread_t pthread = (pthread_t)uthread;
+       pthread->state = PTH_BLK_MUTEX;
        TAILQ_INSERT_TAIL(&__sem->queue, pthread, next);
        mcs_pdr_unlock(&__sem->lock);
 }
@@ -82,7 +83,6 @@ int sem_post (sem_t *__sem)
        mcs_pdr_unlock(&__sem->lock);
 
        if(pthread) {
-               pthread->state = PTH_BLK_MUTEX;
                uthread_runnable((struct uthread*)pthread);
        }
        return 0;