Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kern/include/synch.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ struct lock {
char *lk_name;
HANGMAN_LOCKABLE(lk_hangman); /* Deadlock detector hook. */
// add what you need here
struct thread *lk_owner;
volatile bool lk_locked;
struct semaphore *lk_sem;
// (don't forget to mark things volatile as needed)
};

Expand Down
21 changes: 15 additions & 6 deletions kern/thread/synch.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ lock_create(const char *name)

// add stuff here as needed

lock->lk_locked = false;
lock->lk_owner = NULL;
lock->lk_sem = sem_create(name, 1);
return lock;
}

Expand All @@ -167,7 +170,7 @@ lock_destroy(struct lock *lock)
KASSERT(lock != NULL);

// add stuff here as needed

sem_destroy(lock->lk_sem);
kfree(lock->lk_name);
kfree(lock);
}
Expand All @@ -179,8 +182,10 @@ lock_acquire(struct lock *lock)
//HANGMAN_WAIT(&curthread->t_hangman, &lock->lk_hangman);

// Write this
P(lock->lk_sem);

(void)lock; // suppress warning until code gets written
lock->lk_owner = curthread;
lock->lk_locked = true;

/* Call this (atomically) once the lock is acquired */
//HANGMAN_ACQUIRE(&curthread->t_hangman, &lock->lk_hangman);
Expand All @@ -194,17 +199,21 @@ lock_release(struct lock *lock)

// Write this

(void)lock; // suppress warning until code gets written
lock->lk_locked = false;
lock->lk_owner = NULL;
V(lock->lk_sem);
}

bool
lock_do_i_hold(struct lock *lock)
{
// Write this
(void) lock;
if (curthread == NULL) {
return false;
}

(void)lock; // suppress warning until code gets written

return true; // dummy until code gets written
return (lock->lk_owner == curthread);
}

////////////////////////////////////////////////////////////
Expand Down