From 4e1efd2eaafc3d0958e70ad3c4f4840a29dd8fc5 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 24 Sep 2016 21:19:39 +0200 Subject: [PATCH] Use the wait_list --- kernel/include/conc/mutex.hpp | 15 ++++++++------- kernel/include/conc/semaphore.hpp | 17 +++++++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/kernel/include/conc/mutex.hpp b/kernel/include/conc/mutex.hpp index 483305f2..c2a92acb 100644 --- a/kernel/include/conc/mutex.hpp +++ b/kernel/include/conc/mutex.hpp @@ -8,10 +8,11 @@ #ifndef MUTEX_H #define MUTEX_H -#include +#include #include #include "conc/spinlock.hpp" +#include "conc/wait_list.hpp" #include "scheduler.hpp" #include "logging.hpp" @@ -46,9 +47,9 @@ struct mutex { value_lock.unlock(); } else { - auto pid = scheduler::get_pid(); - queue.push(pid); + queue.enqueue(); + auto pid = scheduler::get_pid(); scheduler::block_process_light(pid); value_lock.unlock(); scheduler::reschedule(); @@ -83,7 +84,7 @@ struct mutex { if (queue.empty()) { value = 1; } else { - auto pid = queue.pop(); + auto pid = queue.dequeue(); scheduler::unblock_process(pid); //No need to increment value, the process won't @@ -92,9 +93,9 @@ struct mutex { } private: - mutable spinlock value_lock; ///< The spin protecting the value - volatile size_t value = 1; ///< The value of the mutex - circular_buffer queue; ///< The sleep queue + mutable spinlock value_lock; ///< The spin protecting the value + volatile size_t value = 1; ///< The value of the mutex + wait_list queue; ///< The sleep queue }; #endif diff --git a/kernel/include/conc/semaphore.hpp b/kernel/include/conc/semaphore.hpp index 059612f8..8cfb61d8 100644 --- a/kernel/include/conc/semaphore.hpp +++ b/kernel/include/conc/semaphore.hpp @@ -8,10 +8,11 @@ #ifndef SEMAPHORE_H #define SEMAPHORE_H -#include +#include #include #include "conc/spinlock.hpp" +#include "conc/wait_list.hpp" #include "scheduler.hpp" @@ -42,9 +43,9 @@ struct semaphore { --value; value_lock.unlock(); } else { - auto pid = scheduler::get_pid(); - queue.push(pid); + queue.enqueue(); + auto pid = scheduler::get_pid(); scheduler::block_process_light(pid); value_lock.unlock(); scheduler::reschedule(); @@ -83,7 +84,7 @@ struct semaphore { ++value; } else { // Wake up the process - auto pid = queue.pop(); + auto pid = queue.dequeue(); scheduler::unblock_process(pid); //No need to increment value, the process won't @@ -104,7 +105,7 @@ struct semaphore { value += n; } else { while (n && !queue.empty()) { - auto pid = queue.pop(); + auto pid = queue.dequeue(); scheduler::unblock_process(pid); --n; } @@ -116,9 +117,9 @@ struct semaphore { } private: - mutable spinlock value_lock; ///< The spin lock protecting the counter - volatile size_t value; ///< The value of the counter - circular_buffer queue; ///< The sleep queue + mutable spinlock value_lock; ///< The spin lock protecting the counter + volatile size_t value; ///< The value of the counter + wait_list queue; ///< The sleep queue }; #endif