mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Fixes static initialization of HAL handles (#565)
This commit is contained in:
committed by
Peter Johnson
parent
abbe630274
commit
237685d4a5
@@ -14,10 +14,13 @@
|
||||
|
||||
namespace hal {
|
||||
static llvm::SmallVector<HandleBase*, 32> globalHandles;
|
||||
static priority_mutex globalHandleMutex;
|
||||
static priority_mutex& GetGlobalHandleMutex() {
|
||||
static priority_mutex globalHandleMutex;
|
||||
return globalHandleMutex;
|
||||
}
|
||||
|
||||
HandleBase::HandleBase() {
|
||||
std::lock_guard<priority_mutex> lock(globalHandleMutex);
|
||||
std::lock_guard<priority_mutex> lock(GetGlobalHandleMutex());
|
||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
||||
if (index == globalHandles.end()) {
|
||||
globalHandles.push_back(this);
|
||||
@@ -27,7 +30,7 @@ HandleBase::HandleBase() {
|
||||
}
|
||||
|
||||
HandleBase::~HandleBase() {
|
||||
std::lock_guard<priority_mutex> lock(globalHandleMutex);
|
||||
std::lock_guard<priority_mutex> lock(GetGlobalHandleMutex());
|
||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
||||
if (index != globalHandles.end()) {
|
||||
*index = nullptr;
|
||||
@@ -42,7 +45,7 @@ void HandleBase::ResetHandles() {
|
||||
}
|
||||
|
||||
void HandleBase::ResetGlobalHandles() {
|
||||
std::unique_lock<priority_mutex> lock(globalHandleMutex);
|
||||
std::unique_lock<priority_mutex> lock(GetGlobalHandleMutex());
|
||||
for (auto&& i : globalHandles) {
|
||||
if (i != nullptr) {
|
||||
lock.unlock();
|
||||
|
||||
Reference in New Issue
Block a user