Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2020 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "wpimath/MathShared.h" |
| 9 | |
| 10 | #include <wpi/mutex.h> |
| 11 | |
| 12 | using namespace wpi::math; |
| 13 | |
| 14 | namespace { |
| 15 | class DefaultMathShared : public MathShared { |
| 16 | public: |
| 17 | void ReportError(const wpi::Twine& error) override {} |
| 18 | void ReportUsage(MathUsageId id, int count) override {} |
| 19 | }; |
| 20 | } // namespace |
| 21 | |
| 22 | static std::unique_ptr<MathShared> mathShared; |
| 23 | static wpi::mutex setLock; |
| 24 | |
| 25 | MathShared& MathSharedStore::GetMathShared() { |
| 26 | std::scoped_lock lock(setLock); |
| 27 | if (!mathShared) mathShared = std::make_unique<DefaultMathShared>(); |
| 28 | return *mathShared; |
| 29 | } |
| 30 | |
| 31 | void MathSharedStore::SetMathShared(std::unique_ptr<MathShared> shared) { |
| 32 | std::scoped_lock lock(setLock); |
| 33 | mathShared = std::move(shared); |
| 34 | } |