blob: 5252e876fc1af39bf0c83b36388c2417f83e7c6b [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// 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 Schuh1e69f942020-11-14 15:06:14 -08004
5#include "wpimath/MathShared.h"
6
7#include <wpi/mutex.h>
8
9using namespace wpi::math;
10
11namespace {
12class DefaultMathShared : public MathShared {
13 public:
Austin Schuh812d0d12021-11-04 20:16:48 -070014 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 Schuh1e69f942020-11-14 15:06:14 -080017 void ReportUsage(MathUsageId id, int count) override {}
18};
19} // namespace
20
21static std::unique_ptr<MathShared> mathShared;
22static wpi::mutex setLock;
23
24MathShared& MathSharedStore::GetMathShared() {
25 std::scoped_lock lock(setLock);
Austin Schuh812d0d12021-11-04 20:16:48 -070026 if (!mathShared) {
27 mathShared = std::make_unique<DefaultMathShared>();
28 }
Austin Schuh1e69f942020-11-14 15:06:14 -080029 return *mathShared;
30}
31
32void MathSharedStore::SetMathShared(std::unique_ptr<MathShared> shared) {
33 std::scoped_lock lock(setLock);
34 mathShared = std::move(shared);
35}