Squashed 'third_party/allwpilib_2019/' changes from e20d96ea4e..b0167e6337
32c62449be Add ArrayRef overloads to new command classes (#2216)
6190fcb237 Run wpiformat (#2218)
012d93b2bd Use an explicit stack instead of recursion when parameterizing splines (#2197)
222669dc2c Fix trapezoidal profile PID controller setpoint bug (#2210)
abe25b795b TrajectoryUtil.toPathweaverJson: Create parent directories (#2214)
354185189c Update ProjectYear to 2020 (#2212)
f14fe434a1 Add (Old) qualifier to old subsystem (#2211)
e874ba9313 Add Color classes for use with AddressableLED (#2127)
96348e835a Fix C++ SendableRegistry::AddChild() (#2207)
d91796f8d2 fix clang-format version number (#2206)
9abce8eb06 Fix subsystem LiveWindow usage (#2202)
8b4508ad53 Use default path for networktables.ini in simulation (#2205)
5b7dd186d2 Add templates for new commands for vscode plugin (#2016)
6ea13ea8f3 ntcore: Add support for local-only operation (#2204)
44bcf7fb4d Java examples: use non-static imports for constants (#2191)
c7a1dfc0bc Add SlewRateLimiter class (#2192)
a12bb447e4 Fail cmake build if python3 generate_numbers.py fails (#2203)
c4bd54ef44 Add JNI binding to suppress driver station error/warning messages (#2200)
f9a11cce5e Remove -no-module-directories flag from javadoc build (#2201)
6008671c30 Report WPILib version as part of usage reporting (#2199)
7b952d599d Add usage reporting for many new things (#2184)
93cdf68694 Add Constants.cpp for MecanumControllerCommand example (#2196)
0c6f24562f Fix bug in ULEB128 decoding (#2195)
bdc1cab013 Add support for configuring SPI Auto Stall Config (#2193)
3259cffc63 Add transform methods to Trajectory (#2187)
67b59f2b31 Minor improvements/fixes to new command framework (#2186)
1ce24a7a2f Add 2020 speed controllers (#2188)
635882a9f7 Add getter for initial pose in Trajectory (#2180)
71a22861eb Use ManagedStatic for CameraServer (#2174)
9cb69c5b46 Add a way to pass in a preconstructed value to ManagedStatic (#2175)
5e08bb28f8 Add docs and lifecycle tasks for faster dev builds (#2182)
ea4d1a39e1 Update characterization values to match real robot (#2183)
31b588d961 Fix ArmFeedforward Javadocs (#2176)
0b80d566ad Use ChipObject HMB function for LED (#2173)
f8294e689b Sim GUI: Add a bit of spacing to the analog inputs (#2170)
b78f115fcf Work around VS2019 16.4.0 bugs (#2171)
b468c51251 Change AddressableLED example to use consistent PWM port (#2168)
023c088290 Add toString() to relevant kinematics classes (#2160)
8a11d13a39 Fix C++ DutyCycleEncoder int constructor (#2166)
daa81c64a7 Minor javadoc fix in SwerveDriveKinematicsConstraint (#2167)
Change-Id: Ied6a4d039f2b95381e1d2124fcc70d52580cc165
git-subtree-dir: third_party/allwpilib_2019
git-subtree-split: b0167e6337135545e7053acb89dd5726accc7dec
diff --git a/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java b/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java
index cf57834..bd555dc 100644
--- a/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java
+++ b/wpiutil/src/main/java/edu/wpi/first/wpiutil/math/MathUtil.java
@@ -19,6 +19,17 @@
* @param low The lower boundary to which to clamp value.
* @param high The higher boundary to which to clamp value.
*/
+ public static int clamp(int value, int low, int high) {
+ return Math.max(low, Math.min(value, high));
+ }
+
+ /**
+ * Returns value clamped between low and high boundaries.
+ *
+ * @param value Value to clamp.
+ * @param low The lower boundary to which to clamp value.
+ * @param high The higher boundary to which to clamp value.
+ */
public static double clamp(double value, double low, double high) {
return Math.max(low, Math.min(value, high));
}
diff --git a/wpiutil/src/main/native/cpp/leb128.cpp b/wpiutil/src/main/native/cpp/leb128.cpp
index ce68ed8..202ee9a 100644
--- a/wpiutil/src/main/native/cpp/leb128.cpp
+++ b/wpiutil/src/main/native/cpp/leb128.cpp
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
-/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
+/* Copyright (c) 2015-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -38,7 +38,7 @@
}
uint64_t ReadUleb128(const char* addr, uint64_t* ret) {
- uint32_t result = 0;
+ uint64_t result = 0;
int shift = 0;
size_t count = 0;
@@ -59,7 +59,7 @@
}
bool ReadUleb128(raw_istream& is, uint64_t* ret) {
- uint32_t result = 0;
+ uint64_t result = 0;
int shift = 0;
while (1) {
diff --git a/wpiutil/src/main/native/cpp/llvm/ManagedStatic.cpp b/wpiutil/src/main/native/cpp/llvm/ManagedStatic.cpp
index 0cfe58a..a8c82bf 100644
--- a/wpiutil/src/main/native/cpp/llvm/ManagedStatic.cpp
+++ b/wpiutil/src/main/native/cpp/llvm/ManagedStatic.cpp
@@ -30,6 +30,22 @@
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);
diff --git a/wpiutil/src/main/native/include/wpi/ManagedStatic.h b/wpiutil/src/main/native/include/wpi/ManagedStatic.h
index b99ad66..28c11fa 100644
--- a/wpiutil/src/main/native/include/wpi/ManagedStatic.h
+++ b/wpiutil/src/main/native/include/wpi/ManagedStatic.h
@@ -43,6 +43,7 @@
mutable const ManagedStaticBase *Next;
void RegisterManagedStatic(void *(*creator)(), void (*deleter)(void*)) const;
+ void RegisterManagedStatic(void *created, void (*deleter)(void*)) const;
public:
/// isConstructed - Return true if this object has not been created yet.
@@ -60,6 +61,12 @@
class Deleter = object_deleter<C>>
class ManagedStatic : public ManagedStaticBase {
public:
+ ManagedStatic() = default;
+
+ ManagedStatic(C* created, void(*deleter)(void*)) {
+ RegisterManagedStatic(created, deleter);
+ }
+
// Accessors.
C &operator*() {
void *Tmp = Ptr.load(std::memory_order_acquire);
diff --git a/wpiutil/src/test/native/ManagedStaticTest.cpp b/wpiutil/src/test/native/ManagedStaticTest.cpp
new file mode 100644
index 0000000..81a4b9c
--- /dev/null
+++ b/wpiutil/src/test/native/ManagedStaticTest.cpp
@@ -0,0 +1,60 @@
+/*----------------------------------------------------------------------------*/
+/* Copyright (c) 2019 FIRST. All Rights Reserved. */
+/* Open Source Software - may be modified and shared by FRC teams. The code */
+/* must be accompanied by the FIRST BSD license file in the root directory of */
+/* the project. */
+/*----------------------------------------------------------------------------*/
+
+#include "wpi/ManagedStatic.h" // NOLINT(build/include_order)
+
+#include "gtest/gtest.h"
+
+static int refCount = 0;
+
+struct StaticTestClass {
+ StaticTestClass() { refCount++; }
+ ~StaticTestClass() { refCount--; }
+
+ void Func() {}
+};
+
+namespace wpi {
+TEST(ManagedStaticTest, LazyDoesNotInitialize) {
+ {
+ refCount = 0;
+ wpi::ManagedStatic<StaticTestClass> managedStatic;
+ ASSERT_EQ(refCount, 0);
+ }
+ ASSERT_EQ(refCount, 0);
+ wpi_shutdown();
+}
+
+TEST(ManagedStaticTest, LazyInitDoesntDestruct) {
+ {
+ refCount = 0;
+ wpi::ManagedStatic<StaticTestClass> managedStatic;
+ ASSERT_EQ(refCount, 0);
+ managedStatic->Func();
+ ASSERT_EQ(refCount, 1);
+ }
+ ASSERT_EQ(refCount, 1);
+ wpi_shutdown();
+ ASSERT_EQ(refCount, 0);
+}
+
+TEST(ManagedStaticTest, EagerInit) {
+ {
+ refCount = 0;
+ StaticTestClass* test = new StaticTestClass{};
+ ASSERT_EQ(refCount, 1);
+ wpi::ManagedStatic<StaticTestClass> managedStatic(
+ test, [](void* val) { delete static_cast<StaticTestClass*>(val); });
+ ASSERT_EQ(refCount, 1);
+ managedStatic->Func();
+ ASSERT_EQ(refCount, 1);
+ }
+ ASSERT_EQ(refCount, 1);
+ wpi_shutdown();
+ ASSERT_EQ(refCount, 0);
+}
+} // namespace wpi