Skip to content

Commit

Permalink
[wpiutil] SendableRegistry: Use ManagedStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jan 27, 2025
1 parent 334e247 commit b73f0b2
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions wpiutil/src/main/native/cpp/sendable/SendableRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <fmt/format.h>

#include "wpi/DenseMap.h"
#include "wpi/ManagedStatic.h"
#include "wpi/SmallVector.h"
#include "wpi/UidVector.h"
#include "wpi/mutex.h"
Expand Down Expand Up @@ -61,23 +62,10 @@ Component& SendableRegistryInst::GetOrAdd(void* sendable,
return *components[compUid - 1];
}

static std::unique_ptr<SendableRegistryInst>& GetInstanceHolder() {
static std::unique_ptr<SendableRegistryInst> instance =
std::make_unique<SendableRegistryInst>();
return instance;
}

static SendableRegistryInst& GetInstance() {
return *GetInstanceHolder();
}

#ifndef __FRC_ROBORIO__
namespace wpi::impl {
void ResetSendableRegistry() {
std::make_unique<SendableRegistryInst>().swap(GetInstanceHolder());
wpi::ManagedStatic<SendableRegistryInst> inst;
return *inst;
}
} // namespace wpi::impl
#endif

void SendableRegistry::EnsureInitialized() {
GetInstance();
Expand Down

0 comments on commit b73f0b2

Please sign in to comment.