artf4156: Replaced synchronization primitives with C++11 equivalents

Change-Id: I90da739347e875efda2a29dd5484b6dda3cd4753
This commit is contained in:
Tyler Veness
2015-06-25 01:54:20 -07:00
committed by James Kuszmaul
parent 7f5ee01d3e
commit 3f59f3472a
61 changed files with 1293 additions and 768 deletions

View File

@@ -12,7 +12,7 @@
#include "HAL/HAL.hpp"
Notifier *Notifier::timerQueueHead = nullptr;
ReentrantSemaphore Notifier::queueSemaphore;
priority_recursive_mutex Notifier::queueMutex;
void *Notifier::m_notifier = nullptr;
int Notifier::refcount = 0;
@@ -26,9 +26,8 @@ Notifier::Notifier(TimerEventHandler handler, void *param) {
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
m_handler = handler;
m_param = param;
m_handlerSemaphore = initializeSemaphore(SEMAPHORE_FULL);
{
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
// do the first time intialization of static variables
if (refcount == 0) {
int32_t status = 0;
@@ -46,7 +45,7 @@ Notifier::Notifier(TimerEventHandler handler, void *param) {
*/
Notifier::~Notifier() {
{
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
DeleteFromQueue();
// Delete the static variables when the last one is going away
@@ -57,11 +56,9 @@ Notifier::~Notifier() {
}
}
// Acquire the semaphore; this makes certain that the handler is
// Acquire the mutex; this makes certain that the handler is
// not being executed by the interrupt manager.
takeSemaphore(m_handlerSemaphore);
// Delete while holding the semaphore so there can be no race.
deleteSemaphore(m_handlerSemaphore);
std::unique_lock<priority_mutex> lock(m_handlerMutex);
}
/**
@@ -96,7 +93,7 @@ void Notifier::ProcessQueue(uint32_t mask, void *params) {
while (true) // keep processing past events until no more
{
{
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
double currentTime = GetClock();
current = timerQueueHead;
if (current == nullptr || current->m_expirationTime > currentTime) {
@@ -112,16 +109,16 @@ void Notifier::ProcessQueue(uint32_t mask, void *params) {
// not periodic; removed from queue
current->m_queued = false;
}
// Take handler semaphore while holding queue semaphore to make sure
// Take handler mutex while holding queue mutex to make sure
// the handler will execute to completion in case we are being deleted.
takeSemaphore(current->m_handlerSemaphore);
current->m_handlerMutex.lock();
}
current->m_handler(current->m_param); // call the event handler
giveSemaphore(current->m_handlerSemaphore);
current->m_handlerMutex.unlock();
}
// reschedule the first item in the queue
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
UpdateAlarm();
}
@@ -206,7 +203,7 @@ void Notifier::DeleteFromQueue() {
* @param delay Seconds to wait before the handler is called.
*/
void Notifier::StartSingle(double delay) {
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
m_periodic = false;
m_period = delay;
DeleteFromQueue();
@@ -222,7 +219,7 @@ void Notifier::StartSingle(double delay) {
* the call to this method.
*/
void Notifier::StartPeriodic(double period) {
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
m_periodic = true;
m_period = period;
DeleteFromQueue();
@@ -240,10 +237,10 @@ void Notifier::StartPeriodic(double period) {
*/
void Notifier::Stop() {
{
Synchronized sync(queueSemaphore);
std::unique_lock<priority_recursive_mutex> sync(queueMutex);
DeleteFromQueue();
}
// Wait for a currently executing handler to complete before returning from
// Stop()
Synchronized sync(m_handlerSemaphore);
std::unique_lock<priority_mutex> sync(m_handlerMutex);
}