mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add a way to pass in a preconstructed value to ManagedStatic (#2175)
A lot of our cases don't need the lazy construction, but do need manual destruction.
This commit is contained in:
committed by
Peter Johnson
parent
5e08bb28f8
commit
9cb69c5b46
@@ -30,6 +30,22 @@ static wpi::mutex* getManagedStaticMutex() {
|
||||
return ManagedStaticMutex;
|
||||
}
|
||||
|
||||
void ManagedStaticBase::RegisterManagedStatic(void* created,
|
||||
void (*Deleter)(void*)) const {
|
||||
std::scoped_lock Lock(*getManagedStaticMutex());
|
||||
|
||||
if (!Ptr.load(std::memory_order_relaxed)) {
|
||||
void *Tmp = created;
|
||||
|
||||
Ptr.store(Tmp, std::memory_order_release);
|
||||
DeleterFn = Deleter;
|
||||
|
||||
// Add to list of managed statics.
|
||||
Next = StaticList;
|
||||
StaticList = this;
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
|
||||
void (*Deleter)(void*)) const {
|
||||
assert(Creator);
|
||||
|
||||
Reference in New Issue
Block a user