diff --git a/hal/src/main/native/shared/handles/HandlesInternal.cpp b/hal/src/main/native/shared/handles/HandlesInternal.cpp index 029797f9e1..dd2b60c0c8 100644 --- a/hal/src/main/native/shared/handles/HandlesInternal.cpp +++ b/hal/src/main/native/shared/handles/HandlesInternal.cpp @@ -13,7 +13,11 @@ #include namespace hal { -static llvm::SmallVector globalHandles; +static llvm::SmallVector& GetGlobalHandles() { + static llvm::SmallVector globalHandles; + return globalHandles; +} + static wpi::mutex& GetGlobalHandleMutex() { static wpi::mutex globalHandleMutex; return globalHandleMutex; @@ -21,6 +25,7 @@ static wpi::mutex& GetGlobalHandleMutex() { HandleBase::HandleBase() { std::lock_guard lock(GetGlobalHandleMutex()); + auto& globalHandles = GetGlobalHandles(); auto index = std::find(globalHandles.begin(), globalHandles.end(), this); if (index == globalHandles.end()) { globalHandles.push_back(this); @@ -31,6 +36,7 @@ HandleBase::HandleBase() { HandleBase::~HandleBase() { std::lock_guard lock(GetGlobalHandleMutex()); + auto& globalHandles = GetGlobalHandles(); auto index = std::find(globalHandles.begin(), globalHandles.end(), this); if (index != globalHandles.end()) { *index = nullptr; @@ -46,6 +52,7 @@ void HandleBase::ResetHandles() { void HandleBase::ResetGlobalHandles() { std::unique_lock lock(GetGlobalHandleMutex()); + auto& globalHandles = GetGlobalHandles(); for (auto&& i : globalHandles) { if (i != nullptr) { lock.unlock();