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

@@ -8,7 +8,6 @@
#include <time.h>
#include "HAL/cpp/Synchronized.hpp"
#include "simulation/simTime.h"
#include "Utility.h"
@@ -62,19 +61,12 @@ Timer::Timer()
: m_startTime (0.0)
, m_accumulatedTime (0.0)
, m_running (false)
, m_semaphore (0)
{
//Creates a semaphore to control access to critical regions.
//Initially 'open'
m_semaphore = initializeMutexNormal();
Reset();
}
Timer::~Timer()
{
deleteMutex(m_semaphore);
}
/**
* Get the current time from the timer. If the clock is running it is derived from
* the current system clock the start time stored in the timer class. If the clock
@@ -87,7 +79,7 @@ double Timer::Get() const
double result;
double currentTime = GetFPGATimestamp();
Synchronized sync(m_semaphore);
std::unique_lock<priority_mutex> sync(m_mutex);
if(m_running)
{
// This math won't work if the timer rolled over (71 minutes after boot).
@@ -109,7 +101,7 @@ double Timer::Get() const
*/
void Timer::Reset()
{
Synchronized sync(m_semaphore);
std::unique_lock<priority_mutex> sync(m_mutex);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
@@ -121,7 +113,7 @@ void Timer::Reset()
*/
void Timer::Start()
{
Synchronized sync(m_semaphore);
std::unique_lock<priority_mutex> sync(m_mutex);
if (!m_running)
{
m_startTime = GetFPGATimestamp();
@@ -139,7 +131,7 @@ void Timer::Stop()
{
double temp = Get();
Synchronized sync(m_semaphore);
std::unique_lock<priority_mutex> sync(m_mutex);
if (m_running)
{
m_accumulatedTime = temp;
@@ -159,7 +151,7 @@ bool Timer::HasPeriodPassed(double period)
{
if (Get() > period)
{
Synchronized sync(m_semaphore);
std::unique_lock<priority_mutex> sync(m_mutex);
// Advance the start time by the period.
// Don't set it to the current time... we want to avoid drift.
m_startTime += period;
@@ -203,8 +195,6 @@ extern "C"
#include "simulation/MainNode.h"
namespace wpilib { namespace internal {
double simTime = 0;
MULTIWAIT_ID time_wait = initializeMultiWait();
MUTEX_ID time_wait_mutex = initializeMutexNormal();
void time_callback(const msgs::ConstFloat64Ptr &msg) {
simTime = msg->data();