Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 4 | |
| 5 | #include "wpimath/MathShared.h" |
| 6 | |
| 7 | #include <wpi/mutex.h> |
| 8 | |
| 9 | using namespace wpi::math; |
| 10 | |
| 11 | namespace { |
| 12 | class DefaultMathShared : public MathShared { |
| 13 | public: |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | void ReportErrorV(fmt::string_view format, fmt::format_args args) override {} |
| 15 | void ReportWarningV(fmt::string_view format, fmt::format_args args) override { |
| 16 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 17 | void ReportUsage(MathUsageId id, int count) override {} |
| 18 | }; |
| 19 | } // namespace |
| 20 | |
| 21 | static std::unique_ptr<MathShared> mathShared; |
| 22 | static wpi::mutex setLock; |
| 23 | |
| 24 | MathShared& MathSharedStore::GetMathShared() { |
| 25 | std::scoped_lock lock(setLock); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 26 | if (!mathShared) { |
| 27 | mathShared = std::make_unique<DefaultMathShared>(); |
| 28 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 29 | return *mathShared; |
| 30 | } |
| 31 | |
| 32 | void MathSharedStore::SetMathShared(std::unique_ptr<MathShared> shared) { |
| 33 | std::scoped_lock lock(setLock); |
| 34 | mathShared = std::move(shared); |
| 35 | } |