Browse Source

i hate the world

tsdedhar 7 years ago
parent
commit
456a00a360
2 changed files with 23 additions and 21 deletions
  1. 5 4
      kern/include/synch.h
  2. 18 17
      kern/thread/synch.c

+ 5 - 4
kern/include/synch.h

@@ -72,10 +72,11 @@ void V(struct semaphore *);
  * The name field is for easier debugging. A copy of the name is
  * (should be) made internally.
  */
-struct lock {
-        char *lk_name;
-        // add what you need here
-        // (don't forget to mark things volatile as needed)
+struct lock
+{
+  char * lk_name;
+  struct wchan * wc;
+  struct thread * volatile owner;
 };
 
 struct lock *lock_create(const char *name);

+ 18 - 17
kern/thread/synch.c

@@ -148,24 +148,25 @@ V(struct semaphore *sem)
 // Lock.
 
 struct lock *
-lock_create(const char *name)
+lock_create(const char * name)
 {
-        struct lock *lock;
-
-        lock = kmalloc(sizeof(struct lock));
-        if (lock == NULL) {
-                return NULL;
-        }
-
-        lock->lk_name = kstrdup(name);
-        if (lock->lk_name == NULL) {
-                kfree(lock);
-                return NULL;
-        }
-        
-        // add stuff here as needed
-        
-        return lock;
+  struct lock * lock = kmalloc(sizeof(struct lock));
+  
+  if (lock == NULL)
+  {
+    return NULL;
+  }
+
+  lock->lk_name = kstrdup(name);
+  
+  struct wchan * wc = wc_create(name);
+  
+  if (lock->lk_name == NULL || wc == NULL)
+  {
+    kfree(lock);
+    kfree(wc);
+    
+  return lock;
 }
 
 void