diff --git a/threads/synch.cc b/threads/synch.cc index 7d5e3e4..4d9bf3a 100644 --- a/threads/synch.cc +++ b/threads/synch.cc @@ -100,10 +100,37 @@ Semaphore::V() // Dummy functions -- so we can compile our later assignments // Note -- without a correct implementation of Condition::Wait(), // the test case in the network assignment won't work! -Lock::Lock(const char* debugName) {} -Lock::~Lock() {} -void Lock::Acquire() {} -void Lock::Release() {} +Lock::Lock(const char* debugName) { + name = debugName; + free = true; + queue = new List; +} +Lock::~Lock() { + delete queue; +} +void Lock::Acquire() { + + // Disable interrupts -- similar to Semaphore P() + + //Check if lock is free and then make it unfree + + //Else check if lock is not free -- add self to queue (while to check for free) + + //Enable Interrupts + +} +void Lock::Release() { + + // Disable interrupts + + //Check if thread has lock... isHeldByCurrentThread? + + //if not, do nothing + + //if yes, release the lock and wakeup 1 of the waiting thread in queue + + //Enable interrupts +} Condition::Condition(const char* debugName) { } Condition::~Condition() { } diff --git a/threads/synch.h b/threads/synch.h index 5b6ee14..14bd587 100644 --- a/threads/synch.h +++ b/threads/synch.h @@ -80,6 +80,11 @@ class Lock { private: char* name; // for debugging // plus some other stuff you'll need to define + //We need a queue, similar to that of Semaphore + List *queue; // threads waiting on lock to become free + //Need to know if the lock is free(avaliable) + bool free; //Checks if lock is free + }; // The following class defines a "condition variable". A condition