mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
artf4156: Replaced synchronization primitives with C++11 equivalents
Change-Id: I90da739347e875efda2a29dd5484b6dda3cd4753
This commit is contained in:
committed by
James Kuszmaul
parent
7f5ee01d3e
commit
3f59f3472a
@@ -10,7 +10,6 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "HAL/cpp/Synchronized.hpp"
|
||||
#include "Utility.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -62,12 +61,9 @@ double GetTime() {
|
||||
Timer::Timer() {
|
||||
// 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
|
||||
@@ -81,7 +77,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) {
|
||||
// If the current time is before the start time, then the FPGA clock
|
||||
// rolled over. Compensate by adding the ~71 minutes that it takes
|
||||
@@ -105,7 +101,7 @@ double Timer::Get() const {
|
||||
* now
|
||||
*/
|
||||
void Timer::Reset() {
|
||||
Synchronized sync(m_semaphore);
|
||||
std::unique_lock<priority_mutex> sync(m_mutex);
|
||||
m_accumulatedTime = 0;
|
||||
m_startTime = GetFPGATimestamp();
|
||||
}
|
||||
@@ -116,7 +112,7 @@ void Timer::Reset() {
|
||||
* relative to the system clock.
|
||||
*/
|
||||
void Timer::Start() {
|
||||
Synchronized sync(m_semaphore);
|
||||
std::unique_lock<priority_mutex> sync(m_mutex);
|
||||
if (!m_running) {
|
||||
m_startTime = GetFPGATimestamp();
|
||||
m_running = true;
|
||||
@@ -132,7 +128,7 @@ void Timer::Start() {
|
||||
void Timer::Stop() {
|
||||
double temp = Get();
|
||||
|
||||
Synchronized sync(m_semaphore);
|
||||
std::unique_lock<priority_mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
m_accumulatedTime = temp;
|
||||
m_running = false;
|
||||
@@ -149,7 +145,7 @@ void Timer::Stop() {
|
||||
*/
|
||||
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.
|
||||
m_startTime += period;
|
||||
// Don't set it to the current time... we want to avoid drift.
|
||||
|
||||
Reference in New Issue
Block a user