mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Remove template types from lock RAII wrapper usages (#1756)
C++17 has template type autodeduction. These wrappers include std::lock_guard and std::unique_lock.
This commit is contained in:
committed by
Peter Johnson
parent
e582518bae
commit
841ef5d739
@@ -131,7 +131,7 @@ template <typename R, typename... T>
|
||||
void WorkerThreadThread<R, T...>::Main() {
|
||||
std::vector<Request> requests;
|
||||
while (m_active) {
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
m_cond.wait(lock, [&] { return !m_active || !m_requests.empty(); });
|
||||
if (!m_active) break;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-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. */
|
||||
@@ -695,7 +695,7 @@ inline future<T> PromiseFactory<T>::CreateFuture(uint64_t request) {
|
||||
|
||||
template <typename T>
|
||||
future<T> PromiseFactory<T>::MakeReadyFuture(T&& value) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
uint64_t req = CreateErasedRequest();
|
||||
m_results.emplace_back(std::piecewise_construct, std::forward_as_tuple(req),
|
||||
std::forward_as_tuple(std::move(value)));
|
||||
@@ -709,7 +709,7 @@ inline promise<T> PromiseFactory<T>::CreatePromise(uint64_t request) {
|
||||
|
||||
template <typename T>
|
||||
void PromiseFactory<T>::SetValue(uint64_t request, const T& value) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
if (!EraseRequest(request)) return;
|
||||
auto it = std::find_if(m_thens.begin(), m_thens.end(),
|
||||
[=](const auto& x) { return x.request == request; });
|
||||
@@ -728,7 +728,7 @@ void PromiseFactory<T>::SetValue(uint64_t request, const T& value) {
|
||||
|
||||
template <typename T>
|
||||
void PromiseFactory<T>::SetValue(uint64_t request, T&& value) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
if (!EraseRequest(request)) return;
|
||||
auto it = std::find_if(m_thens.begin(), m_thens.end(),
|
||||
[=](const auto& x) { return x.request == request; });
|
||||
@@ -748,7 +748,7 @@ void PromiseFactory<T>::SetValue(uint64_t request, T&& value) {
|
||||
template <typename T>
|
||||
void PromiseFactory<T>::SetThen(uint64_t request, uint64_t outRequest,
|
||||
ThenFunction func) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
auto it = std::find_if(m_results.begin(), m_results.end(),
|
||||
[=](const auto& r) { return r.first == request; });
|
||||
if (it != m_results.end()) {
|
||||
@@ -762,7 +762,7 @@ void PromiseFactory<T>::SetThen(uint64_t request, uint64_t outRequest,
|
||||
|
||||
template <typename T>
|
||||
bool PromiseFactory<T>::IsReady(uint64_t request) noexcept {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
auto it = std::find_if(m_results.begin(), m_results.end(),
|
||||
[=](const auto& r) { return r.first == request; });
|
||||
return it != m_results.end();
|
||||
@@ -771,7 +771,7 @@ bool PromiseFactory<T>::IsReady(uint64_t request) noexcept {
|
||||
template <typename T>
|
||||
T PromiseFactory<T>::GetResult(uint64_t request) {
|
||||
// wait for response
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
while (IsActive()) {
|
||||
// Did we get a response to *our* request?
|
||||
auto it = std::find_if(m_results.begin(), m_results.end(),
|
||||
@@ -791,7 +791,7 @@ T PromiseFactory<T>::GetResult(uint64_t request) {
|
||||
template <typename T>
|
||||
void PromiseFactory<T>::WaitResult(uint64_t request) {
|
||||
// wait for response
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
while (IsActive()) {
|
||||
// Did we get a response to *our* request?
|
||||
auto it = std::find_if(m_results.begin(), m_results.end(),
|
||||
@@ -807,7 +807,7 @@ template <class Clock, class Duration>
|
||||
bool PromiseFactory<T>::WaitResultUntil(
|
||||
uint64_t request,
|
||||
const std::chrono::time_point<Clock, Duration>& timeout_time) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
bool timeout = false;
|
||||
while (IsActive()) {
|
||||
// Did we get a response to *our* request?
|
||||
@@ -839,7 +839,7 @@ template <class Clock, class Duration>
|
||||
bool PromiseFactory<void>::WaitResultUntil(
|
||||
uint64_t request,
|
||||
const std::chrono::time_point<Clock, Duration>& timeout_time) {
|
||||
std::unique_lock<wpi::mutex> lock(GetResultMutex());
|
||||
std::unique_lock lock(GetResultMutex());
|
||||
bool timeout = false;
|
||||
while (IsActive()) {
|
||||
// Did we get a response to *our* request?
|
||||
|
||||
@@ -508,7 +508,7 @@ void JCallbackThread<T>::Main() {
|
||||
reinterpret_cast<void**>(&env), &args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !(m_active && m_queue.empty()); });
|
||||
if (!m_active) break;
|
||||
|
||||
@@ -68,7 +68,7 @@ class Async final : public HandleImpl<Async<T...>, uv_async_t> {
|
||||
int err =
|
||||
uv_async_init(loop->GetRaw(), h->GetRaw(), [](uv_async_t* handle) {
|
||||
auto& h = *static_cast<Async*>(handle->data);
|
||||
std::lock_guard<wpi::mutex> lock(h.m_mutex);
|
||||
std::lock_guard lock(h.m_mutex);
|
||||
for (auto&& v : h.m_data) std::apply(h.wakeup, v);
|
||||
h.m_data.clear();
|
||||
});
|
||||
@@ -96,7 +96,7 @@ class Async final : public HandleImpl<Async<T...>, uv_async_t> {
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_data.emplace_back(std::forward_as_tuple(std::forward<U>(u)...));
|
||||
}
|
||||
if (loop) this->Invoke(&uv_async_send, this->GetRaw());
|
||||
|
||||
@@ -81,7 +81,7 @@ class AsyncFunction<R(T...)> final
|
||||
int err =
|
||||
uv_async_init(loop->GetRaw(), h->GetRaw(), [](uv_async_t* handle) {
|
||||
auto& h = *static_cast<AsyncFunction*>(handle->data);
|
||||
std::unique_lock<wpi::mutex> lock(h.m_mutex);
|
||||
std::unique_lock lock(h.m_mutex);
|
||||
|
||||
if (!h.m_params.empty()) {
|
||||
// for each set of parameters in the input queue, call the wakeup
|
||||
@@ -132,7 +132,7 @@ class AsyncFunction<R(T...)> final
|
||||
|
||||
// add the parameters to the input queue
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_params.emplace_back(std::piecewise_construct,
|
||||
std::forward_as_tuple(req),
|
||||
std::forward_as_tuple(std::forward<U>(u)...));
|
||||
|
||||
Reference in New Issue
Block a user