Only call addrspace_destroy() if USERPROG.
[pintos-anon] / src / threads / synch.c
index 39e43c3d57868935224f2a77e7305b96e4cff6b6..ea38068ad017f58888cdf34c9d9f5ce652d4449e 100644 (file)
@@ -1,13 +1,12 @@
 #include "synch.h"
 #include "interrupt.h"
 #include "lib.h"
 #include "synch.h"
 #include "interrupt.h"
 #include "lib.h"
-#include "malloc.h"
 #include "thread.h"
 
 /* One thread in a list. */
 struct thread_elem
   {
 #include "thread.h"
 
 /* One thread in a list. */
 struct thread_elem
   {
-    struct list_elem elem;
+    list_elem elem;
     struct thread *thread;      
   };
 
     struct thread *thread;      
   };
 
@@ -35,11 +34,13 @@ sema_init (struct semaphore *sema, unsigned value, const char *name)
    atomically decrements it.
 
    This function may sleep, so it must not be called within an
    atomically decrements it.
 
    This function may sleep, so it must not be called within an
-   interrupt handler. */
+   interrupt handler.  This function may be called with
+   interrupts disabled, but interrupts will be turned back on if
+   we need to sleep. */
 void
 sema_down (struct semaphore *sema) 
 {
 void
 sema_down (struct semaphore *sema) 
 {
-  enum if_level old_level;
+  enum intr_level old_level;
 
   ASSERT (sema != NULL);
   ASSERT (!intr_context ());
 
   ASSERT (sema != NULL);
   ASSERT (!intr_context ());
@@ -63,14 +64,14 @@ sema_down (struct semaphore *sema)
 void
 sema_up (struct semaphore *sema) 
 {
 void
 sema_up (struct semaphore *sema) 
 {
-  enum if_level old_level;
+  enum intr_level old_level;
 
   ASSERT (sema != NULL);
 
   old_level = intr_disable ();
   if (!list_empty (&sema->waiters)) 
 
   ASSERT (sema != NULL);
 
   old_level = intr_disable ();
   if (!list_empty (&sema->waiters)) 
-    thread_ready (list_entry (list_pop_front (&sema->waiters),
-                              struct thread_elem, elem)->thread);
+    thread_wake (list_entry (list_pop_front (&sema->waiters),
+                             struct thread_elem, elem)->thread);
   sema->value++;
   intr_set_level (old_level);
 }
   sema->value++;
   intr_set_level (old_level);
 }
@@ -117,9 +118,9 @@ sema_self_test (void)
 \f
 /* Initializes LOCK and names it NAME (for debugging purposes).
    A lock can be held by at most a single thread at any given
 \f
 /* Initializes LOCK and names it NAME (for debugging purposes).
    A lock can be held by at most a single thread at any given
-   time.  Our locks are not "recursive", meaning that it is an
-   error for a thread that holds a lock to attempt to reacquire
-   it.
+   time.  Our locks are not "recursive", that is, it is an error
+   for the thread currently holding a lock to try to acquire that
+   lock.
 
    A lock is a specialization of a semaphore with an initial
    value of 1.  The difference between a lock and such a
 
    A lock is a specialization of a semaphore with an initial
    value of 1.  The difference between a lock and such a
@@ -147,11 +148,13 @@ lock_init (struct lock *lock, const char *name)
    thread.
 
    This function may sleep, so it must not be called within an
    thread.
 
    This function may sleep, so it must not be called within an
-   interrupt handler. */
+   interrupt handler.  This function may be called with
+   interrupts disabled, but interrupts will be turned back on if
+   we need to sleep. */
 void
 lock_acquire (struct lock *lock)
 {
 void
 lock_acquire (struct lock *lock)
 {
-  enum if_level old_level;
+  enum intr_level old_level;
 
   ASSERT (lock != NULL);
   ASSERT (!intr_context ());
 
   ASSERT (lock != NULL);
   ASSERT (!intr_context ());
@@ -171,7 +174,7 @@ lock_acquire (struct lock *lock)
 void
 lock_release (struct lock *lock) 
 {
 void
 lock_release (struct lock *lock) 
 {
-  enum if_level old_level;
+  enum intr_level old_level;
 
   ASSERT (lock != NULL);
   ASSERT (lock_held_by_current_thread (lock));
 
   ASSERT (lock != NULL);
   ASSERT (lock_held_by_current_thread (lock));
@@ -205,7 +208,7 @@ lock_name (const struct lock *lock)
 /* One semaphore in a list. */
 struct semaphore_elem 
   {
 /* One semaphore in a list. */
 struct semaphore_elem 
   {
-    struct list_elem elem;
+    list_elem elem;
     struct semaphore semaphore;
   };
 
     struct semaphore semaphore;
   };
 
@@ -240,7 +243,9 @@ cond_init (struct condition *cond, const char *name)
    from locks to condition variables.
 
    This function may sleep, so it must not be called within an
    from locks to condition variables.
 
    This function may sleep, so it must not be called within an
-   interrupt handler. */
+   interrupt handler.  This function may be called with
+   interrupts disabled, but interrupts will be turned back on if
+   we need to sleep. */
 void
 cond_wait (struct condition *cond, struct lock *lock) 
 {
 void
 cond_wait (struct condition *cond, struct lock *lock) 
 {