blob: 8a64f2e40d65311abb0077f6c98d2c5bb618485e [file] [log] [blame]
Austin Schuh1e69f942020-11-14 15:06:14 -08001/*----------------------------------------------------------------------------*/
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
12using namespace wpi::math;
13
14namespace {
15class 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
22static std::unique_ptr<MathShared> mathShared;
23static wpi::mutex setLock;
24
25MathShared& MathSharedStore::GetMathShared() {
26 std::scoped_lock lock(setLock);
27 if (!mathShared) mathShared = std::make_unique<DefaultMathShared>();
28 return *mathShared;
29}
30
31void MathSharedStore::SetMathShared(std::unique_ptr<MathShared> shared) {
32 std::scoped_lock lock(setLock);
33 mathShared = std::move(shared);
34}