Change list_elem from typedef to struct.
[pintos-anon] / src / threads / synch.c
index 7993543016448f5fa55b4ed5378a022e181c0fc6..1504d98859f8b54cc6c6688f5ed1de3227cd97f8 100644 (file)
    MODIFICATIONS.
 */
 
-#include "synch.h"
-#include "interrupt.h"
-#include "thread.h"
-#include "lib/lib.h"
+#include "threads/synch.h"
+#include <stdio.h>
+#include <string.h>
+#include "threads/interrupt.h"
+#include "threads/thread.h"
 
 /* Initializes semaphore SEMA to VALUE and names it NAME (for
    debugging purposes only).  A semaphore is a nonnegative
@@ -105,25 +106,24 @@ sema_name (const struct semaphore *sema)
 static void sema_test_helper (void *sema_);
 
 /* Self-test for semaphores that makes control "ping-pong"
-   between a pair of threads.  Insert calls to printk() to see
+   between a pair of threads.  Insert calls to printf() to see
    what's going on. */
 void
 sema_self_test (void) 
 {
-  struct thread *thread;
   struct semaphore sema[2];
   int i;
 
-  printk ("Testing semaphores...");
+  printf ("Testing semaphores...");
   sema_init (&sema[0], 0, "ping");
   sema_init (&sema[1], 0, "pong");
-  thread = thread_create ("sema-test", sema_test_helper, &sema);
+  thread_create ("sema-test", PRI_DEFAULT, sema_test_helper, &sema);
   for (i = 0; i < 10; i++) 
     {
       sema_up (&sema[0]);
       sema_down (&sema[1]);
     }
-  printk ("done.\n");
+  printf ("done.\n");
 }
 
 /* Thread function used by sema_self_test(). */
@@ -162,7 +162,6 @@ lock_init (struct lock *lock, const char *name)
   ASSERT (lock != NULL);
   ASSERT (name != NULL);
 
-  strlcpy (lock->name, name, sizeof lock->name);
   lock->holder = NULL;
   sema_init (&lock->semaphore, 1, name);
 }
@@ -193,8 +192,8 @@ lock_acquire (struct lock *lock)
 /* Releases LOCK, which must be owned by the current thread.
 
    An interrupt handler cannot acquire a lock, so it does not
-   make sense to try to signal a condition variable within an
-   interrupt handler. */
+   make sense to try to release a lock within an interrupt
+   handler. */
 void
 lock_release (struct lock *lock) 
 {
@@ -226,13 +225,13 @@ lock_name (const struct lock *lock)
 {
   ASSERT (lock != NULL);
 
-  return lock->name;
+  return sema_name (&lock->semaphore);
 }
 \f
 /* One semaphore in a list. */
 struct semaphore_elem 
   {
-    list_elem elem;                     /* List element. */
+    struct list_elem elem;              /* List element. */
     struct semaphore semaphore;         /* This semaphore. */
   };
 
@@ -251,7 +250,7 @@ cond_init (struct condition *cond, const char *name)
 }
 
 /* Atomically releases LOCK and waits for COND to be signaled by
-   some other piece of code.  After COND is signalled, LOCK is
+   some other piece of code.  After COND is signaled, LOCK is
    reacquired before returning.  LOCK must be held before calling
    this function.
 
@@ -262,7 +261,7 @@ cond_init (struct condition *cond, const char *name)
    again.
 
    A given condition variable is associated with only a single
-   lock, but one lock may be be associated with any number of
+   lock, but one lock may be associated with any number of
    condition variables.  That is, there is a one-to-many mapping
    from locks to condition variables.