Moves the HAL priority_ custom types to the hal namespace (#532)

There is a shim for backwards compatibility, just like the frc namespace.
As with the frc namespace, the library compiles without the shim.
This commit is contained in:
Thad House
2017-05-11 21:25:22 -07:00
committed by Peter Johnson
parent 16e71eac43
commit efec0c5cc3
47 changed files with 250 additions and 223 deletions

View File

@@ -17,6 +17,7 @@ model {
targetPlatform 'roborio-arm'
binaries.all {
tasks.withType(CppCompile) {
cppCompiler.args "-DNAMESPACED_PRIORITY"
addNiLibraryLinks(linker, targetPlatform)
addWpiUtilLibraryLinks(it, linker, targetPlatform)
}

View File

@@ -45,7 +45,7 @@ class SerialHelper {
int32_t m_resourceHandle;
static priority_mutex m_nameMutex;
static hal::priority_mutex m_nameMutex;
static std::string m_usbNames[2];
};
} // namespace hal

View File

@@ -22,6 +22,8 @@
#include "priority_mutex.h"
namespace hal {
class priority_condition_variable {
typedef std::chrono::system_clock clock;
@@ -130,3 +132,10 @@ class priority_condition_variable {
Lock& m_lock;
};
};
} // namespace hal
// For backwards compatibility
#ifndef NAMESPACED_PRIORITY
using priority_condition_variable = hal::priority_condition_variable; // NOLINT
#endif

View File

@@ -11,14 +11,18 @@
#include <mutex>
#if defined(FRC_SIMULATOR) || defined(_WIN32)
namespace hal {
// We do not want to use pthreads if in the simulator; however, in the
// simulator, we do not care about priority inversion.
typedef std::mutex priority_mutex;
typedef std::recursive_mutex priority_recursive_mutex;
} // namespace hal
#else // Covers rest of file.
#include <pthread.h>
namespace hal {
class priority_recursive_mutex {
public:
typedef pthread_mutex_t* native_handle_type;
@@ -77,5 +81,12 @@ class priority_mutex {
pthread_mutex_t m_mutex = {{0, 0, 0, 0x20, 0, {0}}};
#endif
};
} // namespace hal
#endif // FRC_SIMULATOR
// For backwards compatibility
#ifndef NAMESPACED_PRIORITY
using priority_mutex = hal::priority_mutex; // NOLINT
using priority_recursive_mutex = hal::priority_recursive_mutex; // NOLINT
#endif

View File

@@ -47,7 +47,7 @@ class DigitalHandleResource {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
std::array<hal::priority_mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size>
@@ -58,7 +58,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -76,7 +76,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -89,7 +89,7 @@ void DigitalHandleResource<THandle, TStruct, size>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
} // namespace hal

View File

@@ -52,7 +52,7 @@ class IndexedClassedHandleResource {
private:
// Dynamic array to shrink HAL file size.
std::unique_ptr<std::shared_ptr<TStruct>[]> m_structures;
std::unique_ptr<priority_mutex[]> m_handleMutexes;
std::unique_ptr<hal::priority_mutex[]> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -60,7 +60,7 @@ template <typename THandle, typename TStruct, int16_t size,
IndexedClassedHandleResource<THandle, TStruct, size,
enumValue>::IndexedClassedHandleResource() {
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
m_handleMutexes = std::make_unique<priority_mutex[]>(size);
m_handleMutexes = std::make_unique<hal::priority_mutex[]>(size);
}
template <typename THandle, typename TStruct, int16_t size,
@@ -73,7 +73,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -92,7 +92,7 @@ std::shared_ptr<TStruct> IndexedClassedHandleResource<
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -106,7 +106,7 @@ void IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
} // namespace hal

View File

@@ -48,7 +48,7 @@ class IndexedHandleResource {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
std::array<hal::priority_mutex, size> m_handleMutexes;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -60,7 +60,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -79,7 +79,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -93,7 +93,7 @@ void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
} // namespace hal

View File

@@ -47,8 +47,8 @@ class LimitedClassedHandleResource {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
priority_mutex m_allocateMutex;
std::array<hal::priority_mutex, size> m_handleMutexes;
hal::priority_mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
@@ -57,12 +57,12 @@ THandle
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
std::shared_ptr<TStruct> toSet) {
// globally lock to loop through indices
std::lock_guard<priority_mutex> sync(m_allocateMutex);
std::lock_guard<hal::priority_mutex> sync(m_allocateMutex);
for (int16_t i = 0; i < size; i++) {
if (m_structures[i] == nullptr) {
// if a false index is found, grab its specific mutex
// and allocate it.
std::lock_guard<priority_mutex> sync(m_handleMutexes[i]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[i]);
m_structures[i] = toSet;
return static_cast<THandle>(createHandle(i, enumValue));
}
@@ -79,7 +79,7 @@ std::shared_ptr<TStruct> LimitedClassedHandleResource<
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -93,8 +93,8 @@ void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<priority_mutex> sync(m_allocateMutex);
std::lock_guard<priority_mutex> lock(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_allocateMutex);
std::lock_guard<hal::priority_mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
} // namespace hal

View File

@@ -45,20 +45,20 @@ class LimitedHandleResource {
private:
std::array<std::shared_ptr<TStruct>, size> m_structures;
std::array<priority_mutex, size> m_handleMutexes;
priority_mutex m_allocateMutex;
std::array<hal::priority_mutex, size> m_handleMutexes;
hal::priority_mutex m_allocateMutex;
};
template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
// globally lock to loop through indices
std::lock_guard<priority_mutex> sync(m_allocateMutex);
std::lock_guard<hal::priority_mutex> sync(m_allocateMutex);
for (int16_t i = 0; i < size; i++) {
if (m_structures[i] == nullptr) {
// if a false index is found, grab its specific mutex
// and allocate it.
std::lock_guard<priority_mutex> sync(m_handleMutexes[i]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[i]);
m_structures[i] = std::make_shared<TStruct>();
return static_cast<THandle>(createHandle(i, enumValue));
}
@@ -75,7 +75,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -89,8 +89,8 @@ void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
int16_t index = getHandleTypedIndex(handle, enumValue);
if (index < 0 || index >= size) return;
// lock and deallocated handle
std::lock_guard<priority_mutex> sync(m_allocateMutex);
std::lock_guard<priority_mutex> lock(m_handleMutexes[index]);
std::lock_guard<hal::priority_mutex> sync(m_allocateMutex);
std::lock_guard<hal::priority_mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
} // namespace hal

View File

@@ -47,13 +47,13 @@ class UnlimitedHandleResource {
private:
std::vector<std::shared_ptr<TStruct>> m_structures;
priority_mutex m_handleMutex;
hal::priority_mutex m_handleMutex;
};
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
std::shared_ptr<TStruct> structure) {
std::lock_guard<priority_mutex> sync(m_handleMutex);
std::lock_guard<hal::priority_mutex> sync(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {
@@ -71,7 +71,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue);
std::lock_guard<priority_mutex> sync(m_handleMutex);
std::lock_guard<hal::priority_mutex> sync(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
return nullptr;
return m_structures[index];
@@ -81,7 +81,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue);
std::lock_guard<priority_mutex> sync(m_handleMutex);
std::lock_guard<hal::priority_mutex> sync(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size())) return;
m_structures[index].reset();
}

View File

@@ -30,7 +30,7 @@ std::unique_ptr<tPWM> pwmSystem;
std::unique_ptr<tSPI> spiSystem;
static std::atomic<bool> digitalSystemsInitialized{false};
static priority_mutex initializeMutex;
static hal::priority_mutex initializeMutex;
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
kNumDigitalChannels + kNumPWMHeaders>
@@ -43,7 +43,7 @@ void initializeDigital(int32_t* status) {
// Initial check, as if it's true initialization has finished
if (digitalSystemsInitialized) return;
std::lock_guard<priority_mutex> lock(initializeMutex);
std::lock_guard<hal::priority_mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (digitalSystemsInitialized) return;

View File

@@ -25,9 +25,9 @@ struct HAL_JoystickAxesInt {
int16_t axes[HAL_kMaxJoystickAxes];
};
static priority_mutex msgMutex;
static priority_condition_variable newDSDataAvailableCond;
static priority_mutex newDSDataAvailableMutex;
static hal::priority_mutex msgMutex;
static hal::priority_condition_variable newDSDataAvailableCond;
static hal::priority_mutex newDSDataAvailableMutex;
static int newDSDataAvailableCounter{0};
extern "C" {
@@ -42,7 +42,7 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
// Avoid flooding console by keeping track of previous 5 error
// messages and only printing again if they're longer than 1 second old.
static constexpr int KEEP_MSGS = 5;
std::lock_guard<priority_mutex> lock(msgMutex);
std::lock_guard<hal::priority_mutex> lock(msgMutex);
static std::string prevMsg[KEEP_MSGS];
static std::chrono::time_point<std::chrono::steady_clock>
prevMsgTime[KEEP_MSGS];
@@ -254,7 +254,7 @@ bool HAL_IsNewControlData(void) {
thread_local int lastCount{-1};
int currentCount = 0;
{
std::unique_lock<priority_mutex> lock(newDSDataAvailableMutex);
std::unique_lock<hal::priority_mutex> lock(newDSDataAvailableMutex);
currentCount = newDSDataAvailableCounter;
}
if (lastCount == currentCount) return false;
@@ -276,7 +276,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
auto timeoutTime =
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
std::unique_lock<priority_mutex> lock(newDSDataAvailableMutex);
std::unique_lock<hal::priority_mutex> lock(newDSDataAvailableMutex);
int currentCount = newDSDataAvailableCounter;
while (newDSDataAvailableCounter == currentCount) {
if (timeout > 0) {
@@ -302,7 +302,7 @@ static int32_t newDataOccur(uint32_t refNum) {
// Since we could get other values, require our specific handle
// to signal our threads
if (refNum != refNumber) return 0;
std::lock_guard<priority_mutex> lock(newDSDataAvailableMutex);
std::lock_guard<hal::priority_mutex> lock(newDSDataAvailableMutex);
// Nofify all threads
newDSDataAvailableCounter++;
newDSDataAvailableCond.notify_all();
@@ -316,11 +316,11 @@ static int32_t newDataOccur(uint32_t refNum) {
*/
void HAL_InitializeDriverStation(void) {
static std::atomic_bool initialized{false};
static priority_mutex initializeMutex;
static hal::priority_mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<priority_mutex> lock(initializeMutex);
std::lock_guard<hal::priority_mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;

View File

@@ -35,7 +35,7 @@ using namespace hal;
static std::unique_ptr<tGlobal> global;
static std::unique_ptr<tSysWatchdog> watchdog;
static priority_mutex timeMutex;
static hal::priority_mutex timeMutex;
static uint32_t timeEpoch = 0;
static uint32_t prevFPGATime = 0;
static HAL_NotifierHandle rolloverNotifier = 0;
@@ -224,7 +224,7 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
*status = NiFpga_Status_ResourceNotInitialized;
return 0;
}
std::lock_guard<priority_mutex> lock(timeMutex);
std::lock_guard<hal::priority_mutex> lock(timeMutex);
uint32_t fpgaTime = global->readLocalTime(status);
if (*status != 0) return 0;
// check for rollover
@@ -270,11 +270,11 @@ static void timerRollover(uint64_t currentTime, HAL_NotifierHandle handle) {
void HAL_BaseInitialize(int32_t* status) {
static std::atomic_bool initialized{false};
static priority_mutex initializeMutex;
static hal::priority_mutex initializeMutex;
// Initial check, as if it's true initialization has finished
if (initialized) return;
std::lock_guard<priority_mutex> lock(initializeMutex);
std::lock_guard<hal::priority_mutex> lock(initializeMutex);
// Second check in case another thread was waiting
if (initialized) return;
// image 4; Fixes errors caused by multiple processes. Talk to NI about this

View File

@@ -26,7 +26,7 @@ using namespace hal;
static const int32_t kTimerInterruptNumber = 28;
static priority_mutex notifierInterruptMutex;
static hal::priority_mutex notifierInterruptMutex;
static priority_recursive_mutex notifierMutex;
static std::unique_ptr<tAlarm> notifierAlarm;
static std::unique_ptr<tInterruptManager> notifierManager;
@@ -182,7 +182,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
if (!notifierAtexitRegistered.test_and_set())
std::atexit(cleanupNotifierAtExit);
if (notifierRefCount.fetch_add(1) == 0) {
std::lock_guard<priority_mutex> sync(notifierInterruptMutex);
std::lock_guard<hal::priority_mutex> sync(notifierInterruptMutex);
// create manager and alarm if not already created
if (!notifierManager) {
notifierManager = std::make_unique<tInterruptManager>(
@@ -254,7 +254,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
}
if (notifierRefCount.fetch_sub(1) == 1) {
std::lock_guard<priority_mutex> sync(notifierInterruptMutex);
std::lock_guard<hal::priority_mutex> sync(notifierInterruptMutex);
// if this was the last notifier, clean up alarm and manager
if (notifierAlarm) {
notifierAlarm->writeEnable(false, status);

View File

@@ -285,7 +285,7 @@ done:
int32_t SerialHelper::GetIndexForPort(HAL_SerialPort port, int32_t* status) {
// Hold lock whenever we're using the names array
std::lock_guard<priority_mutex> lock(m_nameMutex);
std::lock_guard<hal::priority_mutex> lock(m_nameMutex);
std::string portString = m_usbNames[port - 2];

View File

@@ -7,6 +7,8 @@
#include "HAL/cpp/priority_mutex.h"
using namespace hal;
void priority_recursive_mutex::lock() { pthread_mutex_lock(&m_mutex); }
void priority_recursive_mutex::unlock() { pthread_mutex_unlock(&m_mutex); }

View File

@@ -13,6 +13,7 @@ model {
targetPlatform 'roborio-arm'
binaries.all {
tasks.withType(CppCompile) {
cppCompiler.args "-DNAMESPACED_PRIORITY"
addNiLibraryLinks(linker, targetPlatform)
addNetworkTablesLibraryLinks(it, linker, targetPlatform)
addCsCoreLibraryLinks(it, linker, targetPlatform)

View File

@@ -14,6 +14,7 @@ model {
tasks.withType(CppCompile) {
dependsOn generateCppVersion
cppCompiler.args "-DNAMESPACED_WPILIB"
cppCompiler.args "-DNAMESPACED_PRIORITY"
addNiLibraryLinks(linker, targetPlatform)
addNetworkTablesLibraryLinks(it, linker, targetPlatform)
addCsCoreLibraryLinks(it, linker, targetPlatform)

View File

@@ -49,7 +49,7 @@ class DigitalGlitchFilter : public SensorBase {
void DoAdd(DigitalSource* input, int requested_index);
int m_channelIndex = -1;
static priority_mutex m_mutex;
static hal::priority_mutex m_mutex;
static ::std::array<bool, 3> m_filterAllocated;
};

View File

@@ -117,7 +117,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
std::thread m_dsThread;
std::atomic<bool> m_isRunning{false};
mutable priority_mutex m_joystickDataMutex;
mutable hal::priority_mutex m_joystickDataMutex;
// Robot state status variables
bool m_userInDisabled = false;
@@ -128,7 +128,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
// Control word variables
mutable HAL_ControlWord m_controlWordCache;
mutable std::chrono::steady_clock::time_point m_lastControlWordUpdate;
mutable priority_mutex m_controlWordMutex;
mutable hal::priority_mutex m_controlWordMutex;
double m_nextMessageTime = 0;
};

View File

@@ -37,13 +37,13 @@ class MotorSafetyHelper : public ErrorBase {
// the FPGA clock value when this motor has expired
double m_stopTime;
// protect accesses to the state for this object
mutable priority_recursive_mutex m_syncMutex;
mutable hal::priority_recursive_mutex m_syncMutex;
// the object that is using the helper
MotorSafety* m_safeObject;
// List of all existing MotorSafetyHelper objects.
static std::set<MotorSafetyHelper*> m_helperList;
// protect accesses to the list of helpers
static priority_recursive_mutex m_listMutex;
static hal::priority_recursive_mutex m_listMutex;
};
} // namespace frc

View File

@@ -44,9 +44,9 @@ class Notifier : public ErrorBase {
static void Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle);
// used to constrain execution between destructors and callback
static priority_mutex m_destructorMutex;
static hal::priority_mutex m_destructorMutex;
// held while updating process information
priority_mutex m_processMutex;
hal::priority_mutex m_processMutex;
// HAL handle, atomic for proper destruction
std::atomic<HAL_NotifierHandle> m_notifier{0};
// address of the handler

View File

@@ -22,10 +22,10 @@ using namespace frc;
std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
{false, false, false}};
priority_mutex DigitalGlitchFilter::m_mutex;
hal::priority_mutex DigitalGlitchFilter::m_mutex;
DigitalGlitchFilter::DigitalGlitchFilter() {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
auto index =
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
wpi_assert(index != m_filterAllocated.end());
@@ -38,7 +38,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
DigitalGlitchFilter::~DigitalGlitchFilter() {
if (m_channelIndex >= 0) {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
m_filterAllocated[m_channelIndex] = false;
}
}

View File

@@ -90,7 +90,7 @@ double DriverStation::GetStickAxis(int stick, int axis) {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::unique_lock<priority_mutex> lock(m_joystickDataMutex);
std::unique_lock<hal::priority_mutex> lock(m_joystickDataMutex);
if (axis >= m_joystickAxes[stick].count) {
// Unlock early so error printing isn't locked.
m_joystickDataMutex.unlock();
@@ -116,7 +116,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::unique_lock<priority_mutex> lock(m_joystickDataMutex);
std::unique_lock<hal::priority_mutex> lock(m_joystickDataMutex);
if (pov >= m_joystickPOVs[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -142,7 +142,7 @@ int DriverStation::GetStickButtons(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return m_joystickButtons[stick].buttons;
}
@@ -163,7 +163,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
return false;
}
std::unique_lock<priority_mutex> lock(m_joystickDataMutex);
std::unique_lock<hal::priority_mutex> lock(m_joystickDataMutex);
if (button > m_joystickButtons[stick].count) {
// Unlock early so error printing isn't locked.
lock.unlock();
@@ -187,7 +187,7 @@ int DriverStation::GetStickAxisCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return m_joystickAxes[stick].count;
}
@@ -202,7 +202,7 @@ int DriverStation::GetStickPOVCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return m_joystickPOVs[stick].count;
}
@@ -217,7 +217,7 @@ int DriverStation::GetStickButtonCount(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return 0;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return m_joystickButtons[stick].count;
}
@@ -232,7 +232,7 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return false;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return static_cast<bool>(m_joystickDescriptor[stick].isXbox);
}
@@ -247,7 +247,7 @@ int DriverStation::GetJoystickType(int stick) const {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return static_cast<int>(m_joystickDescriptor[stick].type);
}
@@ -261,7 +261,7 @@ std::string DriverStation::GetJoystickName(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
std::string retVal(m_joystickDescriptor[stick].name);
return retVal;
}
@@ -277,7 +277,7 @@ int DriverStation::GetJoystickAxisType(int stick, int axis) const {
wpi_setWPIError(BadJoystickIndex);
return -1;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
return m_joystickDescriptor[stick].axisTypes[axis];
}
@@ -528,7 +528,7 @@ void DriverStation::GetData() {
UpdateControlWord(true, controlWord);
// Obtain a write lock on the data, swap the cached data into the
// main data arrays
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_joystickDataMutex);
m_joystickAxes.swap(m_joystickAxesCache);
m_joystickPOVs.swap(m_joystickPOVsCache);
m_joystickButtons.swap(m_joystickButtonsCache);
@@ -629,7 +629,7 @@ void DriverStation::Run() {
void DriverStation::UpdateControlWord(bool force,
HAL_ControlWord& controlWord) const {
auto now = std::chrono::steady_clock::now();
std::lock_guard<priority_mutex> lock(m_controlWordMutex);
std::lock_guard<hal::priority_mutex> lock(m_controlWordMutex);
// Update every 50 ms or on force.
if ((now - m_lastControlWordUpdate > std::chrono::milliseconds(50)) ||
force) {

View File

@@ -17,7 +17,7 @@
using namespace frc;
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
priority_recursive_mutex MotorSafetyHelper::m_listMutex;
hal::priority_recursive_mutex MotorSafetyHelper::m_listMutex;
/**
* The constructor for a MotorSafetyHelper object.
@@ -37,12 +37,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
m_expiration = DEFAULT_SAFETY_EXPIRATION;
m_stopTime = Timer::GetFPGATimestamp();
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
m_helperList.insert(this);
}
MotorSafetyHelper::~MotorSafetyHelper() {
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
m_helperList.erase(this);
}
@@ -51,7 +51,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
* Resets the timer on this object that is used to do the timeouts.
*/
void MotorSafetyHelper::Feed() {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
}
@@ -60,7 +60,7 @@ void MotorSafetyHelper::Feed() {
* @param expirationTime The timeout value in seconds.
*/
void MotorSafetyHelper::SetExpiration(double expirationTime) {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_expiration = expirationTime;
}
@@ -69,7 +69,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
* @return the timeout value in seconds.
*/
double MotorSafetyHelper::GetExpiration() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return m_expiration;
}
@@ -79,7 +79,7 @@ double MotorSafetyHelper::GetExpiration() const {
* timed out.
*/
bool MotorSafetyHelper::IsAlive() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
}
@@ -93,7 +93,7 @@ void MotorSafetyHelper::Check() {
DriverStation& ds = DriverStation::GetInstance();
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
if (m_stopTime < Timer::GetFPGATimestamp()) {
std::ostringstream desc;
m_safeObject->GetDescription(desc);
@@ -109,7 +109,7 @@ void MotorSafetyHelper::Check() {
* @param enabled True if motor safety is enforced for this object
*/
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_enabled = enabled;
}
@@ -119,7 +119,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
* @return True if motor safety is enforced for this device
*/
bool MotorSafetyHelper::IsSafetyEnabled() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return m_enabled;
}
@@ -129,7 +129,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
* any that have timed out.
*/
void MotorSafetyHelper::CheckMotors() {
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
for (auto elem : m_helperList) {
elem->Check();
}

View File

@@ -14,7 +14,7 @@
using namespace frc;
priority_mutex Notifier::m_destructorMutex;
hal::priority_mutex Notifier::m_destructorMutex;
/**
* Create a Notifier for timer event notification.
@@ -44,8 +44,8 @@ Notifier::~Notifier() {
/* Acquire the mutex; this makes certain that the handler is not being
* executed by the interrupt manager.
*/
std::lock_guard<priority_mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<priority_mutex> lock(m_processMutex);
std::lock_guard<hal::priority_mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<hal::priority_mutex> lock(m_processMutex);
}
/**
@@ -68,7 +68,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
Notifier* notifier;
{
// Lock static mutex to grab the notifier param
std::lock_guard<priority_mutex> lock(Notifier::m_destructorMutex);
std::lock_guard<hal::priority_mutex> lock(Notifier::m_destructorMutex);
int32_t status = 0;
auto notifierPointer = HAL_GetNotifierParam(handle, &status);
if (notifierPointer == nullptr) return;
@@ -95,7 +95,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
* @param delay Seconds to wait before the handler is called.
*/
void Notifier::StartSingle(double delay) {
std::lock_guard<priority_mutex> sync(m_processMutex);
std::lock_guard<hal::priority_mutex> sync(m_processMutex);
m_periodic = false;
m_period = delay;
m_expirationTime = GetClock() + m_period;
@@ -113,7 +113,7 @@ void Notifier::StartSingle(double delay) {
* after the call to this method.
*/
void Notifier::StartPeriodic(double period) {
std::lock_guard<priority_mutex> sync(m_processMutex);
std::lock_guard<hal::priority_mutex> sync(m_processMutex);
m_periodic = true;
m_period = period;
m_expirationTime = GetClock() + m_period;
@@ -136,6 +136,6 @@ void Notifier::Stop() {
// Wait for a currently executing handler to complete before returning from
// Stop()
std::lock_guard<priority_mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<priority_mutex> lock(m_processMutex);
std::lock_guard<hal::priority_mutex> lockStatic(Notifier::m_destructorMutex);
std::lock_guard<hal::priority_mutex> lock(m_processMutex);
}

View File

@@ -90,7 +90,7 @@ void PIDController::Calculate() {
PIDOutput* pidOutput;
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
pidInput = m_pidInput;
pidOutput = m_pidOutput;
enabled = m_enabled;
@@ -100,7 +100,7 @@ void PIDController::Calculate() {
if (pidOutput == nullptr) return;
if (enabled) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
double input = pidInput->PIDGet();
double result;
PIDOutput* pidOutput;
@@ -197,7 +197,7 @@ double PIDController::CalculateFeedForward() {
*/
void PIDController::SetPID(double p, double i, double d) {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -222,7 +222,7 @@ void PIDController::SetPID(double p, double i, double d) {
*/
void PIDController::SetPID(double p, double i, double d, double f) {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -243,7 +243,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
* @return proportional coefficient
*/
double PIDController::GetP() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_P;
}
@@ -253,7 +253,7 @@ double PIDController::GetP() const {
* @return integral coefficient
*/
double PIDController::GetI() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_I;
}
@@ -263,7 +263,7 @@ double PIDController::GetI() const {
* @return differential coefficient
*/
double PIDController::GetD() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_D;
}
@@ -273,7 +273,7 @@ double PIDController::GetD() const {
* @return Feed forward coefficient
*/
double PIDController::GetF() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_F;
}
@@ -285,7 +285,7 @@ double PIDController::GetF() const {
* @return the latest calculated output
*/
double PIDController::Get() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_result;
}
@@ -299,7 +299,7 @@ double PIDController::Get() const {
* @param continuous true turns on continuous, false turns off continuous
*/
void PIDController::SetContinuous(bool continuous) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_continuous = continuous;
}
@@ -311,7 +311,7 @@ void PIDController::SetContinuous(bool continuous) {
*/
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_minimumInput = minimumInput;
m_maximumInput = maximumInput;
}
@@ -326,7 +326,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
* @param maximumOutput the maximum value to write to the output
*/
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_minimumOutput = minimumOutput;
m_maximumOutput = maximumOutput;
}
@@ -340,7 +340,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
*/
void PIDController::SetSetpoint(double setpoint) {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
if (m_maximumInput > m_minimumInput) {
if (setpoint > m_maximumInput)
@@ -369,7 +369,7 @@ void PIDController::SetSetpoint(double setpoint) {
* @return the current setpoint
*/
double PIDController::GetSetpoint() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_setpoint;
}
@@ -379,7 +379,7 @@ double PIDController::GetSetpoint() const {
* @return the change in setpoint over time
*/
double PIDController::GetDeltaSetpoint() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
}
@@ -391,7 +391,7 @@ double PIDController::GetDeltaSetpoint() const {
double PIDController::GetError() const {
double setpoint = GetSetpoint();
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return GetContinuousError(setpoint - m_pidInput->PIDGet());
}
}
@@ -422,7 +422,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
double PIDController::GetAvgError() const {
double avgError = 0;
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
// Don't divide by zero.
if (m_buf.size()) avgError = m_bufTotal / m_buf.size();
}
@@ -436,7 +436,7 @@ double PIDController::GetAvgError() const {
* @param percentage error which is tolerable
*/
void PIDController::SetTolerance(double percent) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -448,7 +448,7 @@ void PIDController::SetTolerance(double percent) {
* @param percentage error which is tolerable
*/
void PIDController::SetAbsoluteTolerance(double absTolerance) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_toleranceType = kAbsoluteTolerance;
m_tolerance = absTolerance;
}
@@ -460,7 +460,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
* @param percentage error which is tolerable
*/
void PIDController::SetPercentTolerance(double percent) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -476,7 +476,7 @@ void PIDController::SetPercentTolerance(double percent) {
* @param bufLength Number of previous cycles to average. Defaults to 1.
*/
void PIDController::SetToleranceBuffer(int bufLength) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_bufLength = bufLength;
// Cut the buffer down to size if needed.
@@ -498,7 +498,7 @@ void PIDController::SetToleranceBuffer(int bufLength) {
* This will return false until at least one input value has been computed.
*/
bool PIDController::OnTarget() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
if (m_buf.size() == 0) return false;
double error = GetAvgError();
switch (m_toleranceType) {
@@ -521,7 +521,7 @@ bool PIDController::OnTarget() const {
*/
void PIDController::Enable() {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_enabled = true;
}
@@ -535,7 +535,7 @@ void PIDController::Enable() {
*/
void PIDController::Disable() {
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_pidOutput->PIDWrite(0);
m_enabled = false;
}
@@ -549,7 +549,7 @@ void PIDController::Disable() {
* Return true if PIDController is enabled.
*/
bool PIDController::IsEnabled() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return m_enabled;
}
@@ -559,7 +559,7 @@ bool PIDController::IsEnabled() const {
void PIDController::Reset() {
Disable();
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_prevError = 0;
m_totalError = 0;
m_result = 0;

View File

@@ -80,7 +80,7 @@ double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::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
@@ -104,7 +104,7 @@ double Timer::Get() const {
* now.
*/
void Timer::Reset() {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
@@ -116,7 +116,7 @@ void Timer::Reset() {
* relative to the system clock.
*/
void Timer::Start() {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_running = true;
@@ -133,7 +133,7 @@ void Timer::Start() {
void Timer::Stop() {
double temp = Get();
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
if (m_running) {
m_accumulatedTime = temp;
m_running = false;
@@ -150,7 +150,7 @@ void Timer::Stop() {
*/
bool Timer::HasPeriodPassed(double period) {
if (Get() > period) {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::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.

View File

@@ -53,11 +53,11 @@ class Scheduler : public ErrorBase, public NamedSendable {
void ProcessCommandAddition(Command* command);
Command::SubsystemSet m_subsystems;
priority_mutex m_buttonsLock;
hal::priority_mutex m_buttonsLock;
typedef std::vector<ButtonScheduler*> ButtonVector;
ButtonVector m_buttons;
typedef std::vector<Command*> CommandVector;
priority_mutex m_additionsLock;
hal::priority_mutex m_additionsLock;
CommandVector m_additions;
typedef std::set<Command*> CommandSet;
CommandSet m_commands;

View File

@@ -113,7 +113,7 @@ class ErrorBase {
protected:
mutable Error m_error;
// TODO: Replace globalError with a global list of all errors.
static priority_mutex _globalErrorMutex;
static hal::priority_mutex _globalErrorMutex;
static Error _globalError;
};

View File

@@ -136,7 +136,7 @@ class PIDController : public LiveWindowSendable,
std::queue<double> m_buf;
double m_bufTotal = 0;
mutable priority_recursive_mutex m_mutex;
mutable hal::priority_recursive_mutex m_mutex;
std::unique_ptr<Notifier> m_controlLoop;
Timer m_setpointTimer;

View File

@@ -43,9 +43,9 @@ class Resource : public ErrorBase {
private:
std::vector<bool> m_isAllocated;
priority_recursive_mutex m_allocateLock;
hal::priority_recursive_mutex m_allocateLock;
static priority_recursive_mutex m_createLock;
static hal::priority_recursive_mutex m_createLock;
};
} // namespace frc

View File

@@ -51,7 +51,7 @@ class Timer {
double m_startTime = 0.0;
double m_accumulatedTime = 0.0;
bool m_running = false;
mutable priority_mutex m_mutex;
mutable hal::priority_mutex m_mutex;
};
} // namespace frc

View File

@@ -41,7 +41,7 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
* @param command The command to be scheduled
*/
void Scheduler::AddCommand(Command* command) {
std::lock_guard<priority_mutex> sync(m_additionsLock);
std::lock_guard<hal::priority_mutex> sync(m_additionsLock);
if (std::find(m_additions.begin(), m_additions.end(), command) !=
m_additions.end())
return;
@@ -49,7 +49,7 @@ void Scheduler::AddCommand(Command* command) {
}
void Scheduler::AddButton(ButtonScheduler* button) {
std::lock_guard<priority_mutex> sync(m_buttonsLock);
std::lock_guard<hal::priority_mutex> sync(m_buttonsLock);
m_buttons.push_back(button);
}
@@ -115,7 +115,7 @@ void Scheduler::Run() {
{
if (!m_enabled) return;
std::lock_guard<priority_mutex> sync(m_buttonsLock);
std::lock_guard<hal::priority_mutex> sync(m_buttonsLock);
for (auto rButtonIter = m_buttons.rbegin(); rButtonIter != m_buttons.rend();
rButtonIter++) {
(*rButtonIter)->Execute();
@@ -138,7 +138,7 @@ void Scheduler::Run() {
// Add the new things
{
std::lock_guard<priority_mutex> sync(m_additionsLock);
std::lock_guard<hal::priority_mutex> sync(m_additionsLock);
for (auto additionsIter = m_additions.begin();
additionsIter != m_additions.end(); additionsIter++) {
ProcessCommandAddition(*additionsIter);

View File

@@ -18,7 +18,7 @@
using namespace frc;
priority_mutex ErrorBase::_globalErrorMutex;
hal::priority_mutex ErrorBase::_globalErrorMutex;
Error ErrorBase::_globalError;
/**
@@ -62,7 +62,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
m_error.Set(-1, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -90,7 +90,7 @@ void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
m_error.Set(success, err.str(), filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -115,7 +115,7 @@ void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -153,7 +153,7 @@ void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange,
delete[] buf;
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -179,7 +179,7 @@ void ErrorBase::SetWPIError(llvm::StringRef errorMessage, Error::Code code,
m_error.Set(code, err, filename, function, lineNumber, this);
// Update the global error if there is not one already set.
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() == 0) {
_globalError.Clone(m_error);
}
@@ -201,7 +201,7 @@ void ErrorBase::SetGlobalError(Error::Code code, llvm::StringRef contextMessage,
llvm::StringRef function, int lineNumber) {
// If there was an error
if (code != 0) {
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
// Set the current error information for this object.
_globalError.Set(code, contextMessage, filename, function, lineNumber,
@@ -215,7 +215,7 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
llvm::StringRef function, int lineNumber) {
std::string err = errorMessage.str() + ": " + contextMessage.str();
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
if (_globalError.GetCode() != 0) {
_globalError.Clear();
}
@@ -226,6 +226,6 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
* Retrieve the current global error.
*/
Error& ErrorBase::GetGlobalError() {
std::lock_guard<priority_mutex> mutex(_globalErrorMutex);
std::lock_guard<hal::priority_mutex> mutex(_globalErrorMutex);
return _globalError;
}

View File

@@ -12,7 +12,7 @@
using namespace frc;
priority_recursive_mutex Resource::m_createLock;
hal::priority_recursive_mutex Resource::m_createLock;
/**
* Allocate storage for a new instance of Resource.
@@ -22,7 +22,7 @@ priority_recursive_mutex Resource::m_createLock;
* elements - 1].
*/
Resource::Resource(uint32_t elements) {
std::lock_guard<priority_recursive_mutex> sync(m_createLock);
std::lock_guard<hal::priority_recursive_mutex> sync(m_createLock);
m_isAllocated = std::vector<bool>(elements, false);
}
@@ -39,7 +39,7 @@ Resource::Resource(uint32_t elements) {
*/
/*static*/ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
uint32_t elements) {
std::lock_guard<priority_recursive_mutex> sync(m_createLock);
std::lock_guard<hal::priority_recursive_mutex> sync(m_createLock);
if (!r) {
r = std::make_unique<Resource>(elements);
}
@@ -53,7 +53,7 @@ Resource::Resource(uint32_t elements) {
* allocated.
*/
uint32_t Resource::Allocate(const std::string& resourceDesc) {
std::lock_guard<priority_recursive_mutex> sync(m_allocateLock);
std::lock_guard<hal::priority_recursive_mutex> sync(m_allocateLock);
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
if (!m_isAllocated[i]) {
m_isAllocated[i] = true;
@@ -71,7 +71,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
* verified unallocated, then returned.
*/
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
std::lock_guard<priority_recursive_mutex> sync(m_allocateLock);
std::lock_guard<hal::priority_recursive_mutex> sync(m_allocateLock);
if (index >= m_isAllocated.size()) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
return std::numeric_limits<uint32_t>::max();
@@ -92,7 +92,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
* be reused somewhere else in the program.
*/
void Resource::Free(uint32_t index) {
std::unique_lock<priority_recursive_mutex> sync(m_allocateLock);
std::unique_lock<hal::priority_recursive_mutex> sync(m_allocateLock);
if (index == std::numeric_limits<uint32_t>::max()) return;
if (index >= m_isAllocated.size()) {
wpi_setWPIError(NotAllocated);

View File

@@ -37,12 +37,12 @@ class MotorSafetyHelper : public ErrorBase {
// the FPGA clock value when this motor has expired
double m_stopTime;
// protect accesses to the state for this object
mutable priority_recursive_mutex m_syncMutex;
mutable hal::priority_recursive_mutex m_syncMutex;
MotorSafety* m_safeObject; // the object that is using the helper
// List of all existing MotorSafetyHelper objects.
static std::set<MotorSafetyHelper*> m_helperList;
// protect accesses to the list of helpers
static priority_recursive_mutex m_listMutex;
static hal::priority_recursive_mutex m_listMutex;
};
} // namespace frc

View File

@@ -39,8 +39,8 @@ class Notifier : public ErrorBase {
private:
static std::list<Notifier*> timerQueue;
static priority_recursive_mutex queueMutex;
static priority_mutex halMutex;
static hal::priority_recursive_mutex queueMutex;
static hal::priority_mutex halMutex;
static void* m_notifier;
static std::atomic<int> refcount;
@@ -67,7 +67,7 @@ class Notifier : public ErrorBase {
// Indicates if this entry is queued
bool m_queued = false;
// Held by interrupt manager task while handler call is in progress
priority_mutex m_handlerMutex;
hal::priority_mutex m_handlerMutex;
static std::thread m_task;
static std::atomic<bool> m_stopped;
static void Run();

View File

@@ -295,7 +295,7 @@ bool DriverStation::WaitForData(double timeout) {
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
#endif
std::unique_lock<priority_mutex> lock(m_waitForDataMutex);
std::unique_lock<hal::priority_mutex> lock(m_waitForDataMutex);
while (!m_updatedControlLoopData) {
if (timeout > 0) {
auto timedOut = m_waitForDataCond.wait_until(lock, timeoutTime);
@@ -368,7 +368,7 @@ void DriverStation::stateCallback(
*state = *msg;
}
{
std::lock_guard<priority_mutex> lock(m_waitForDataMutex);
std::lock_guard<hal::priority_mutex> lock(m_waitForDataMutex);
m_updatedControlLoopData = true;
}
m_waitForDataCond.notify_all();

View File

@@ -17,7 +17,7 @@
using namespace frc;
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
priority_recursive_mutex MotorSafetyHelper::m_listMutex;
hal::priority_recursive_mutex MotorSafetyHelper::m_listMutex;
/**
* The constructor for a MotorSafetyHelper object.
@@ -37,12 +37,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
m_expiration = DEFAULT_SAFETY_EXPIRATION;
m_stopTime = Timer::GetFPGATimestamp();
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
m_helperList.insert(this);
}
MotorSafetyHelper::~MotorSafetyHelper() {
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
m_helperList.erase(this);
}
@@ -52,7 +52,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
* Resets the timer on this object that is used to do the timeouts.
*/
void MotorSafetyHelper::Feed() {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
}
@@ -62,7 +62,7 @@ void MotorSafetyHelper::Feed() {
* @param expirationTime The timeout value in seconds.
*/
void MotorSafetyHelper::SetExpiration(double expirationTime) {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_expiration = expirationTime;
}
@@ -72,7 +72,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
* @return the timeout value in seconds.
*/
double MotorSafetyHelper::GetExpiration() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return m_expiration;
}
@@ -83,7 +83,7 @@ double MotorSafetyHelper::GetExpiration() const {
* timed out.
*/
bool MotorSafetyHelper::IsAlive() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
}
@@ -98,7 +98,7 @@ void MotorSafetyHelper::Check() {
DriverStation& ds = DriverStation::GetInstance();
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
if (m_stopTime < Timer::GetFPGATimestamp()) {
std::ostringstream desc;
m_safeObject->GetDescription(desc);
@@ -116,7 +116,7 @@ void MotorSafetyHelper::Check() {
* @param enabled True if motor safety is enforced for this object
*/
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
m_enabled = enabled;
}
@@ -128,7 +128,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
* @return True if motor safety is enforced for this device
*/
bool MotorSafetyHelper::IsSafetyEnabled() const {
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
return m_enabled;
}
@@ -139,7 +139,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
* any that have timed out.
*/
void MotorSafetyHelper::CheckMotors() {
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
for (auto elem : m_helperList) {
elem->Check();
}

View File

@@ -14,7 +14,7 @@
using namespace frc;
std::list<Notifier*> Notifier::timerQueue;
priority_recursive_mutex Notifier::queueMutex;
hal::priority_recursive_mutex Notifier::queueMutex;
std::atomic<int> Notifier::refcount{0};
std::thread Notifier::m_task;
std::atomic<bool> Notifier::m_stopped(false);
@@ -34,7 +34,7 @@ Notifier::Notifier(TimerEventHandler handler) {
m_period = 0;
m_queued = false;
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
// do the first time intialization of static variables
if (refcount.fetch_add(1) == 0) {
m_task = std::thread(Run);
@@ -50,7 +50,7 @@ Notifier::Notifier(TimerEventHandler handler) {
*/
Notifier::~Notifier() {
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
DeleteFromQueue();
// Delete the static variables when the last one is going away
@@ -62,7 +62,7 @@ Notifier::~Notifier() {
// Acquire the semaphore; this makes certain that the handler is
// not being executed by the interrupt manager.
std::lock_guard<priority_mutex> lock(m_handlerMutex);
std::lock_guard<hal::priority_mutex> lock(m_handlerMutex);
}
/**
@@ -89,7 +89,7 @@ void Notifier::ProcessQueue(int mask, void* params) {
// keep processing events until no more
while (true) {
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
double currentTime = GetClock();
if (timerQueue.empty()) {
@@ -120,7 +120,7 @@ void Notifier::ProcessQueue(int mask, void* params) {
current->m_handlerMutex.unlock();
}
// reschedule the first item in the queue
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
UpdateAlarm();
}
@@ -202,7 +202,7 @@ void Notifier::DeleteFromQueue() {
* @param delay Seconds to wait before the handler is called.
*/
void Notifier::StartSingle(double delay) {
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
m_periodic = false;
m_period = delay;
DeleteFromQueue();
@@ -220,7 +220,7 @@ void Notifier::StartSingle(double delay) {
* the call to this method.
*/
void Notifier::StartPeriodic(double period) {
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
m_periodic = true;
m_period = period;
DeleteFromQueue();
@@ -237,12 +237,12 @@ void Notifier::StartPeriodic(double period) {
*/
void Notifier::Stop() {
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
DeleteFromQueue();
}
// Wait for a currently executing handler to complete before returning from
// Stop()
std::lock_guard<priority_mutex> sync(m_handlerMutex);
std::lock_guard<hal::priority_mutex> sync(m_handlerMutex);
}
void Notifier::Run() {
@@ -250,13 +250,13 @@ void Notifier::Run() {
Notifier::ProcessQueue(0, nullptr);
bool isEmpty;
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
isEmpty = timerQueue.empty();
}
if (!isEmpty) {
double expirationTime;
{
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
expirationTime = timerQueue.front()->m_expirationTime;
}
Wait(expirationTime - GetClock());

View File

@@ -103,7 +103,7 @@ void PIDController::Calculate() {
PIDSource* pidInput;
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
if (m_pidInput == 0) return;
if (m_pidOutput == 0) return;
enabled = m_enabled;
@@ -116,7 +116,7 @@ void PIDController::Calculate() {
PIDOutput* pidOutput;
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
m_error = m_setpoint - input;
if (m_continuous) {
if (std::fabs(m_error) > (m_maximumInput - m_minimumInput) / 2) {
@@ -212,7 +212,7 @@ double PIDController::CalculateFeedForward() {
*/
void PIDController::SetPID(double p, double i, double d) {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -237,7 +237,7 @@ void PIDController::SetPID(double p, double i, double d) {
*/
void PIDController::SetPID(double p, double i, double d, double f) {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -258,7 +258,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
* @return proportional coefficient
*/
double PIDController::GetP() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_P;
}
@@ -268,7 +268,7 @@ double PIDController::GetP() const {
* @return integral coefficient
*/
double PIDController::GetI() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_I;
}
@@ -278,7 +278,7 @@ double PIDController::GetI() const {
* @return differential coefficient
*/
double PIDController::GetD() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_D;
}
@@ -288,7 +288,7 @@ double PIDController::GetD() const {
* @return Feed forward coefficient
*/
double PIDController::GetF() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_F;
}
@@ -300,7 +300,7 @@ double PIDController::GetF() const {
* @return the latest calculated output
*/
double PIDController::Get() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_result;
}
@@ -314,7 +314,7 @@ double PIDController::Get() const {
* @param continuous Set to true turns on continuous, false turns off continuous
*/
void PIDController::SetContinuous(bool continuous) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_continuous = continuous;
}
@@ -326,7 +326,7 @@ void PIDController::SetContinuous(bool continuous) {
*/
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_minimumInput = minimumInput;
m_maximumInput = maximumInput;
}
@@ -341,7 +341,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
* @param maximumOutput the maximum value to write to the output
*/
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_minimumOutput = minimumOutput;
m_maximumOutput = maximumOutput;
}
@@ -353,7 +353,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
*/
void PIDController::SetSetpoint(double setpoint) {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
if (m_maximumInput > m_minimumInput) {
if (setpoint > m_maximumInput)
@@ -378,7 +378,7 @@ void PIDController::SetSetpoint(double setpoint) {
* @return the current setpoint
*/
double PIDController::GetSetpoint() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_setpoint;
}
@@ -388,7 +388,7 @@ double PIDController::GetSetpoint() const {
* @return the change in setpoint over time
*/
double PIDController::GetDeltaSetpoint() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
}
@@ -400,7 +400,7 @@ double PIDController::GetDeltaSetpoint() const {
double PIDController::GetError() const {
double setpoint = GetSetpoint();
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
return GetContinuousError(setpoint - m_pidInput->PIDGet());
}
}
@@ -432,7 +432,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
double PIDController::GetAvgError() const {
double avgError = 0;
{
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
// Don't divide by zero.
if (m_buf.size()) avgError = m_bufTotal / m_buf.size();
}
@@ -446,7 +446,7 @@ double PIDController::GetAvgError() const {
* @param percent percentage error which is tolerable
*/
void PIDController::SetTolerance(double percent) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -458,7 +458,7 @@ void PIDController::SetTolerance(double percent) {
* @param absTolerance absolute error which is tolerable
*/
void PIDController::SetAbsoluteTolerance(double absTolerance) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_toleranceType = kAbsoluteTolerance;
m_tolerance = absTolerance;
}
@@ -470,7 +470,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
* @param percent percentage error which is tolerable
*/
void PIDController::SetPercentTolerance(double percent) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -486,7 +486,7 @@ void PIDController::SetPercentTolerance(double percent) {
* @param bufLength Number of previous cycles to average. Defaults to 1.
*/
void PIDController::SetToleranceBuffer(int bufLength) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_bufLength = bufLength;
// Cut the buffer down to size if needed.
@@ -506,7 +506,7 @@ void PIDController::SetToleranceBuffer(int bufLength) {
* period of time.
*/
bool PIDController::OnTarget() const {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
if (m_buf.size() == 0) return false;
double error = GetError();
switch (m_toleranceType) {
@@ -528,7 +528,7 @@ bool PIDController::OnTarget() const {
*/
void PIDController::Enable() {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_enabled = true;
}
@@ -542,7 +542,7 @@ void PIDController::Enable() {
*/
void PIDController::Disable() {
{
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_pidOutput->PIDWrite(0);
m_enabled = false;
}
@@ -556,7 +556,7 @@ void PIDController::Disable() {
* Return true if PIDController is enabled.
*/
bool PIDController::IsEnabled() const {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
return m_enabled;
}
@@ -566,7 +566,7 @@ bool PIDController::IsEnabled() const {
void PIDController::Reset() {
Disable();
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
m_prevError = 0;
m_totalError = 0;
m_result = 0;

View File

@@ -98,7 +98,7 @@ double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
if (m_running) {
// This math won't work if the timer rolled over (71 minutes after boot).
// TODO: Check for it and compensate.
@@ -117,7 +117,7 @@ double Timer::Get() const {
* now.
*/
void Timer::Reset() {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
@@ -129,7 +129,7 @@ void Timer::Reset() {
* relative to the system clock.
*/
void Timer::Start() {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_running = true;
@@ -146,7 +146,7 @@ void Timer::Start() {
void Timer::Stop() {
double temp = Get();
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::priority_mutex> sync(m_mutex);
if (m_running) {
m_accumulatedTime = temp;
m_running = false;
@@ -163,7 +163,7 @@ void Timer::Stop() {
*/
bool Timer::HasPeriodPassed(double period) {
if (Get() > period) {
std::lock_guard<priority_mutex> sync(m_mutex);
std::lock_guard<hal::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;

View File

@@ -15,6 +15,7 @@ model {
binaries.all {
tasks.withType(CppCompile) {
cppCompiler.args "-DNAMESPACED_WPILIB"
cppCompiler.args "-DNAMESPACED_PRIORITY"
addNiLibraryLinks(linker, targetPlatform)
addNetworkTablesLibraryLinks(it, linker, targetPlatform)
addCsCoreLibraryLinks(it, linker, targetPlatform)

View File

@@ -23,13 +23,13 @@ namespace testing {
// does work.
class ConditionVariableTest : public ::testing::Test {
protected:
typedef std::unique_lock<priority_mutex> priority_lock;
typedef std::unique_lock<hal::priority_mutex> priority_lock;
// Condition variable to test.
priority_condition_variable m_cond;
hal::priority_condition_variable m_cond;
// Mutex to pass to condition variable when waiting.
priority_mutex m_mutex;
hal::priority_mutex m_mutex;
// flags for testing when threads are completed.
std::atomic<bool> m_done1{false}, m_done2{false};

View File

@@ -25,21 +25,21 @@ class Notification {
public:
// Efficiently waits until the Notification has been notified once.
void Wait() {
std::unique_lock<priority_mutex> lock(m_mutex);
std::unique_lock<hal::priority_mutex> lock(m_mutex);
while (!m_set) {
m_condition.wait(lock);
}
}
// Sets the condition to true, and wakes all waiting threads.
void Notify() {
std::lock_guard<priority_mutex> lock(m_mutex);
std::lock_guard<hal::priority_mutex> lock(m_mutex);
m_set = true;
m_condition.notify_all();
}
private:
// priority_mutex used for the notification and to protect the bit.
priority_mutex m_mutex;
// hal::priority_mutex used for the notification and to protect the bit.
hal::priority_mutex m_mutex;
// Condition for threads to sleep on.
std::condition_variable_any m_condition;
// Bool which is true when the notification has been notified.
@@ -87,7 +87,7 @@ class LowPriorityThread {
bool success() { return m_success.load(); }
private:
// priority_mutex to grab and release.
// hal::priority_mutex to grab and release.
MutexType* m_mutex;
Notification m_started;
// Atomic type used to signal when the thread should unlock the mutex.
@@ -226,7 +226,7 @@ class InversionTestRunner {
// Priority inversion test.
TEST(MutexTest, DISABLED_PriorityInversionTest) {
InversionTestRunner<priority_mutex> runner;
InversionTestRunner<hal::priority_mutex> runner;
std::thread runner_thread(std::ref(runner));
runner_thread.join();
EXPECT_TRUE(runner.success());
@@ -242,7 +242,7 @@ TEST(MutexTest, DISABLED_StdMutexPriorityInversionTest) {
// Smoke test to make sure that mutexes lock and unlock.
TEST(MutexTest, TryLock) {
priority_mutex m;
hal::priority_mutex m;
m.lock();
EXPECT_FALSE(m.try_lock());
m.unlock();
@@ -251,7 +251,7 @@ TEST(MutexTest, TryLock) {
// Priority inversion test.
TEST(MutexTest, DISABLED_ReentrantPriorityInversionTest) {
InversionTestRunner<priority_recursive_mutex> runner;
InversionTestRunner<hal::priority_recursive_mutex> runner;
std::thread runner_thread(std::ref(runner));
runner_thread.join();
EXPECT_TRUE(runner.success());
@@ -259,7 +259,7 @@ TEST(MutexTest, DISABLED_ReentrantPriorityInversionTest) {
// Smoke test to make sure that mutexes lock and unlock.
TEST(MutexTest, ReentrantTryLock) {
priority_recursive_mutex m;
hal::priority_recursive_mutex m;
m.lock();
EXPECT_TRUE(m.try_lock());
m.unlock();

View File

@@ -34,6 +34,7 @@ model {
binaries.all {
tasks.withType(CppCompile) {
dependsOn jniHeaders
cppCompiler.args "-DNAMESPACED_PRIORITY"
addNiLibraryLinks(linker, targetPlatform)
addWpiUtilLibraryLinks(it, linker, targetPlatform)
}