[wpilibc] Add mechanism to reset various global structures (#4007)

This commit is contained in:
Dustin Spicuzza
2022-02-10 01:14:12 -05:00
committed by GitHub
parent 4e3cc25012
commit 74de97eeca
4 changed files with 51 additions and 6 deletions

View File

@@ -48,11 +48,23 @@ struct Instance {
};
} // namespace
static Instance& GetInstance() {
static Instance instance;
static std::unique_ptr<Instance>& GetInstanceHolder() {
static std::unique_ptr<Instance> instance = std::make_unique<Instance>();
return instance;
}
static Instance& GetInstance() {
return *GetInstanceHolder();
}
#ifndef __FRC_ROBORIO__
namespace frc::impl {
void ResetLiveWindow() {
std::make_unique<Instance>().swap(GetInstanceHolder());
}
} // namespace frc::impl
#endif
std::shared_ptr<Component> Instance::GetOrAdd(wpi::Sendable* sendable) {
auto data = std::static_pointer_cast<Component>(
wpi::SendableRegistry::GetData(sendable, dataHandle));