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:
Tyler Veness
2019-07-07 19:17:14 -07:00
committed by Peter Johnson
parent e582518bae
commit 841ef5d739
90 changed files with 621 additions and 621 deletions

View File

@@ -74,7 +74,7 @@ class CallbackThread : public wpi::SafeThread {
struct Poller {
void Terminate() {
{
std::lock_guard<wpi::mutex> lock(poll_mutex);
std::lock_guard lock(poll_mutex);
terminating = true;
}
poll_cond.notify_all();
@@ -94,7 +94,7 @@ class CallbackThread : public wpi::SafeThread {
auto poller = m_pollers[poller_uid];
if (!poller) return;
{
std::lock_guard<wpi::mutex> lock(poller->poll_mutex);
std::lock_guard lock(poller->poll_mutex);
poller->poll_queue.emplace(std::forward<Args>(args)...);
}
poller->poll_cond.notify_one();
@@ -104,7 +104,7 @@ class CallbackThread : public wpi::SafeThread {
template <typename Derived, typename TUserInfo, typename TListenerData,
typename TNotifierData>
void CallbackThread<Derived, TUserInfo, TListenerData, TNotifierData>::Main() {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
while (m_active) {
while (m_queue.empty()) {
m_cond.wait(lock);
@@ -241,7 +241,7 @@ class CallbackManager {
if (!poller) return infos;
}
std::unique_lock<wpi::mutex> lock(poller->poll_mutex);
std::unique_lock lock(poller->poll_mutex);
auto timeout_time = std::chrono::steady_clock::now() +
std::chrono::duration<double>(timeout);
*timed_out = false;
@@ -286,7 +286,7 @@ class CallbackManager {
}
{
std::lock_guard<wpi::mutex> lock(poller->poll_mutex);
std::lock_guard lock(poller->poll_mutex);
poller->cancelling = true;
}
poller->poll_cond.notify_one();

View File

@@ -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. */
@@ -119,7 +119,7 @@ void DispatcherBase::StartServer(
const Twine& persist_filename,
std::unique_ptr<wpi::NetworkAcceptor> acceptor) {
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
if (m_active) return;
m_active = true;
}
@@ -151,7 +151,7 @@ void DispatcherBase::StartServer(
void DispatcherBase::StartClient() {
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
if (m_active) return;
m_active = true;
}
@@ -170,7 +170,7 @@ void DispatcherBase::Stop() {
// wake up client thread with a reconnect
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_client_connector = nullptr;
}
ClientReconnect();
@@ -184,7 +184,7 @@ void DispatcherBase::Stop() {
std::vector<std::shared_ptr<INetworkConnection>> conns;
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
conns.swap(m_connections);
}
@@ -202,14 +202,14 @@ void DispatcherBase::SetUpdateRate(double interval) {
}
void DispatcherBase::SetIdentity(const Twine& name) {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_identity = name.str();
}
void DispatcherBase::Flush() {
auto now = std::chrono::steady_clock::now();
{
std::lock_guard<wpi::mutex> lock(m_flush_mutex);
std::lock_guard lock(m_flush_mutex);
// don't allow flushes more often than every 10 ms
if ((now - m_last_flush) < std::chrono::milliseconds(10)) return;
m_last_flush = now;
@@ -222,7 +222,7 @@ std::vector<ConnectionInfo> DispatcherBase::GetConnections() const {
std::vector<ConnectionInfo> conns;
if (!m_active) return conns;
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
for (auto& conn : m_connections) {
if (conn->state() != NetworkConnection::kActive) continue;
conns.emplace_back(conn->info());
@@ -234,7 +234,7 @@ std::vector<ConnectionInfo> DispatcherBase::GetConnections() const {
bool DispatcherBase::IsConnected() const {
if (!m_active) return false;
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
for (auto& conn : m_connections) {
if (conn->state() == NetworkConnection::kActive) return true;
}
@@ -245,7 +245,7 @@ bool DispatcherBase::IsConnected() const {
unsigned int DispatcherBase::AddListener(
std::function<void(const ConnectionNotification& event)> callback,
bool immediate_notify) const {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
unsigned int uid = m_notifier.Add(callback);
// perform immediate notifications
if (immediate_notify) {
@@ -259,7 +259,7 @@ unsigned int DispatcherBase::AddListener(
unsigned int DispatcherBase::AddPolledListener(unsigned int poller_uid,
bool immediate_notify) const {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
unsigned int uid = m_notifier.AddPolled(poller_uid);
// perform immediate notifications
if (immediate_notify) {
@@ -272,17 +272,17 @@ unsigned int DispatcherBase::AddPolledListener(unsigned int poller_uid,
}
void DispatcherBase::SetConnector(Connector connector) {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_client_connector = std::move(connector);
}
void DispatcherBase::SetConnectorOverride(Connector connector) {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_client_connector_override = std::move(connector);
}
void DispatcherBase::ClearConnectorOverride() {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_client_connector_override = nullptr;
}
@@ -319,7 +319,7 @@ void DispatcherBase::DispatchThreadMain() {
}
{
std::lock_guard<wpi::mutex> user_lock(m_user_mutex);
std::lock_guard user_lock(m_user_mutex);
bool reconnect = false;
if (++count > 10) {
@@ -350,7 +350,7 @@ void DispatcherBase::DispatchThreadMain() {
void DispatcherBase::QueueOutgoing(std::shared_ptr<Message> msg,
INetworkConnection* only,
INetworkConnection* except) {
std::lock_guard<wpi::mutex> user_lock(m_user_mutex);
std::lock_guard user_lock(m_user_mutex);
for (auto& conn : m_connections) {
if (conn.get() == except) continue;
if (only && conn.get() != only) continue;
@@ -392,7 +392,7 @@ void DispatcherBase::ServerThreadMain() {
std::bind(&IStorage::ProcessIncoming, &m_storage, _1, _2,
std::weak_ptr<NetworkConnection>(conn)));
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
// reuse dead connection slots
bool placed = false;
for (auto& c : m_connections) {
@@ -417,7 +417,7 @@ void DispatcherBase::ClientThreadMain() {
// get next server to connect to
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
if (m_client_connector_override) {
connect = m_client_connector_override;
} else {
@@ -439,7 +439,7 @@ void DispatcherBase::ClientThreadMain() {
DEBUG("client connected");
m_networkMode = NT_NET_MODE_CLIENT;
std::unique_lock<wpi::mutex> lock(m_user_mutex);
std::unique_lock lock(m_user_mutex);
using namespace std::placeholders;
auto conn = std::make_shared<NetworkConnection>(
++m_connections_uid, std::move(stream), m_notifier, m_logger,
@@ -469,7 +469,7 @@ bool DispatcherBase::ClientHandshake(
// get identity
std::string self_id;
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
self_id = m_identity;
}
@@ -576,7 +576,7 @@ bool DispatcherBase::ServerHandshake(
// Start with server hello. TODO: initial connection flag
if (proto_rev >= 0x0300) {
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
outgoing.emplace_back(Message::ServerHello(0u, m_identity));
}
@@ -633,7 +633,7 @@ bool DispatcherBase::ServerHandshake(
void DispatcherBase::ClientReconnect(unsigned int proto_rev) {
if ((m_networkMode & NT_NET_MODE_SERVER) != 0) return;
{
std::lock_guard<wpi::mutex> lock(m_user_mutex);
std::lock_guard lock(m_user_mutex);
m_reconnect_proto_rev = proto_rev;
m_do_reconnect = true;
}

View File

@@ -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. */
@@ -63,7 +63,7 @@ void DsClient::Thread::Main() {
std::chrono::steady_clock::now() + std::chrono::milliseconds(500);
unsigned int port;
{
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
m_cond.wait_until(lock, timeout_time, [&] { return !m_active; });
port = m_port;
}

View File

@@ -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. */
@@ -43,7 +43,7 @@ InstanceImpl* InstanceImpl::Get(int inst) {
}
// slow path
std::lock_guard<wpi::mutex> lock(s_mutex);
std::lock_guard lock(s_mutex);
// static fast-path block
if (static_cast<unsigned int>(inst) <
@@ -66,7 +66,7 @@ int InstanceImpl::GetDefaultIndex() {
if (inst >= 0) return inst;
// slow path
std::lock_guard<wpi::mutex> lock(s_mutex);
std::lock_guard lock(s_mutex);
// double-check
inst = s_default;
@@ -79,7 +79,7 @@ int InstanceImpl::GetDefaultIndex() {
}
int InstanceImpl::Alloc() {
std::lock_guard<wpi::mutex> lock(s_mutex);
std::lock_guard lock(s_mutex);
return AllocImpl();
}
@@ -96,7 +96,7 @@ int InstanceImpl::AllocImpl() {
}
void InstanceImpl::Destroy(int inst) {
std::lock_guard<wpi::mutex> lock(s_mutex);
std::lock_guard lock(s_mutex);
if (inst < 0 || static_cast<unsigned int>(inst) >= s_instances.size()) return;
if (static_cast<unsigned int>(inst) <

View File

@@ -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. */
@@ -49,7 +49,7 @@ void NetworkConnection::Start() {
while (!m_outgoing.empty()) m_outgoing.pop();
// reset shutdown flags
{
std::lock_guard<wpi::mutex> lock(m_shutdown_mutex);
std::lock_guard lock(m_shutdown_mutex);
m_read_shutdown = false;
m_write_shutdown = false;
}
@@ -68,7 +68,7 @@ void NetworkConnection::Stop() {
m_outgoing.push(Outgoing());
// wait for threads to terminate, with timeout
if (m_write_thread.joinable()) {
std::unique_lock<wpi::mutex> lock(m_shutdown_mutex);
std::unique_lock lock(m_shutdown_mutex);
auto timeout_time =
std::chrono::steady_clock::now() + std::chrono::milliseconds(200);
if (m_write_shutdown_cv.wait_until(lock, timeout_time,
@@ -78,7 +78,7 @@ void NetworkConnection::Stop() {
m_write_thread.detach(); // timed out, detach it
}
if (m_read_thread.joinable()) {
std::unique_lock<wpi::mutex> lock(m_shutdown_mutex);
std::unique_lock lock(m_shutdown_mutex);
auto timeout_time =
std::chrono::steady_clock::now() + std::chrono::milliseconds(200);
if (m_read_shutdown_cv.wait_until(lock, timeout_time,
@@ -104,12 +104,12 @@ void NetworkConnection::set_proto_rev(unsigned int proto_rev) {
}
NetworkConnection::State NetworkConnection::state() const {
std::lock_guard<wpi::mutex> lock(m_state_mutex);
std::lock_guard lock(m_state_mutex);
return m_state;
}
void NetworkConnection::set_state(State state) {
std::lock_guard<wpi::mutex> lock(m_state_mutex);
std::lock_guard lock(m_state_mutex);
// Don't update state any more once we've died
if (m_state == kDead) return;
// One-shot notify state changes
@@ -121,12 +121,12 @@ void NetworkConnection::set_state(State state) {
}
std::string NetworkConnection::remote_id() const {
std::lock_guard<wpi::mutex> lock(m_remote_id_mutex);
std::lock_guard lock(m_remote_id_mutex);
return m_remote_id;
}
void NetworkConnection::set_remote_id(StringRef remote_id) {
std::lock_guard<wpi::mutex> lock(m_remote_id_mutex);
std::lock_guard lock(m_remote_id_mutex);
m_remote_id = remote_id;
}
@@ -177,7 +177,7 @@ void NetworkConnection::ReadThreadMain() {
done:
// use condition variable to signal thread shutdown
{
std::lock_guard<wpi::mutex> lock(m_shutdown_mutex);
std::lock_guard lock(m_shutdown_mutex);
m_read_shutdown = true;
m_read_shutdown_cv.notify_one();
}
@@ -214,14 +214,14 @@ void NetworkConnection::WriteThreadMain() {
// use condition variable to signal thread shutdown
{
std::lock_guard<wpi::mutex> lock(m_shutdown_mutex);
std::lock_guard lock(m_shutdown_mutex);
m_write_shutdown = true;
m_write_shutdown_cv.notify_one();
}
}
void NetworkConnection::QueueOutgoing(std::shared_ptr<Message> msg) {
std::lock_guard<wpi::mutex> lock(m_pending_mutex);
std::lock_guard lock(m_pending_mutex);
// Merge with previous. One case we don't combine: delete/assign loop.
switch (msg->type()) {
@@ -317,7 +317,7 @@ void NetworkConnection::QueueOutgoing(std::shared_ptr<Message> msg) {
}
void NetworkConnection::PostOutgoing(bool keep_alive) {
std::lock_guard<wpi::mutex> lock(m_pending_mutex);
std::lock_guard lock(m_pending_mutex);
auto now = std::chrono::steady_clock::now();
if (m_pending_outgoing.empty()) {
if (!keep_alive) return;

View File

@@ -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. */
@@ -64,7 +64,7 @@ class RpcServerThread
RpcIdPair lookup_uid{local_id, call_uid};
callback(data);
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto i = m_response_map.find(lookup_uid);
if (i != m_response_map.end()) {
// post an empty response and erase it

View File

@@ -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. */
@@ -30,7 +30,7 @@ Storage::~Storage() {
}
void Storage::SetDispatcher(IDispatcher* dispatcher, bool server) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_dispatcher = dispatcher;
m_server = server;
}
@@ -38,7 +38,7 @@ void Storage::SetDispatcher(IDispatcher* dispatcher, bool server) {
void Storage::ClearDispatcher() { m_dispatcher = nullptr; }
NT_Type Storage::GetMessageEntryType(unsigned int id) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (id >= m_idmap.size()) return NT_UNASSIGNED;
Entry* entry = m_idmap[id];
if (!entry || !entry->value) return NT_UNASSIGNED;
@@ -86,7 +86,7 @@ void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingEntryAssign(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
unsigned int id = msg->id();
StringRef name = msg->str();
Entry* entry;
@@ -211,7 +211,7 @@ void Storage::ProcessIncomingEntryAssign(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingEntryUpdate(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
unsigned int id = msg->id();
if (id >= m_idmap.size() || !m_idmap[id]) {
// ignore arbitrary entry updates;
@@ -248,7 +248,7 @@ void Storage::ProcessIncomingEntryUpdate(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingFlagsUpdate(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
unsigned int id = msg->id();
if (id >= m_idmap.size() || !m_idmap[id]) {
// ignore arbitrary entry updates;
@@ -272,7 +272,7 @@ void Storage::ProcessIncomingFlagsUpdate(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingEntryDelete(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
unsigned int id = msg->id();
if (id >= m_idmap.size() || !m_idmap[id]) {
// ignore arbitrary entry updates;
@@ -296,7 +296,7 @@ void Storage::ProcessIncomingEntryDelete(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingClearEntries(std::shared_ptr<Message> msg,
INetworkConnection* conn) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
// update local
DeleteAllEntriesImpl(false);
@@ -312,7 +312,7 @@ void Storage::ProcessIncomingClearEntries(std::shared_ptr<Message> msg,
void Storage::ProcessIncomingExecuteRpc(
std::shared_ptr<Message> msg, INetworkConnection* /*conn*/,
std::weak_ptr<INetworkConnection> conn_weak) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (!m_server) return; // only process on server
unsigned int id = msg->id();
if (id >= m_idmap.size() || !m_idmap[id]) {
@@ -351,7 +351,7 @@ void Storage::ProcessIncomingExecuteRpc(
void Storage::ProcessIncomingRpcResponse(std::shared_ptr<Message> msg,
INetworkConnection* /*conn*/) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_server) return; // only process on client
unsigned int id = msg->id();
if (id >= m_idmap.size() || !m_idmap[id]) {
@@ -374,7 +374,7 @@ void Storage::ProcessIncomingRpcResponse(std::shared_ptr<Message> msg,
void Storage::GetInitialAssignments(
INetworkConnection& conn, std::vector<std::shared_ptr<Message>>* msgs) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
conn.set_state(INetworkConnection::kSynchronized);
for (auto& i : m_entries) {
Entry* entry = i.getValue();
@@ -388,7 +388,7 @@ void Storage::GetInitialAssignments(
void Storage::ApplyInitialAssignments(
INetworkConnection& conn, wpi::ArrayRef<std::shared_ptr<Message>> msgs,
bool /*new_server*/, std::vector<std::shared_ptr<Message>>* out_msgs) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_server) return; // should not do this on server
conn.set_state(INetworkConnection::kSynchronized);
@@ -476,14 +476,14 @@ void Storage::ApplyInitialAssignments(
}
std::shared_ptr<Value> Storage::GetEntryValue(StringRef name) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) return nullptr;
return i->getValue()->value;
}
std::shared_ptr<Value> Storage::GetEntryValue(unsigned int local_id) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (local_id >= m_localmap.size()) return nullptr;
return m_localmap[local_id]->value;
}
@@ -492,7 +492,7 @@ bool Storage::SetDefaultEntryValue(StringRef name,
std::shared_ptr<Value> value) {
if (name.empty()) return false;
if (!value) return false;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
Entry* entry = GetOrNew(name);
// we return early if value already exists; if types match return true
@@ -505,7 +505,7 @@ bool Storage::SetDefaultEntryValue(StringRef name,
bool Storage::SetDefaultEntryValue(unsigned int local_id,
std::shared_ptr<Value> value) {
if (!value) return false;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return false;
Entry* entry = m_localmap[local_id].get();
@@ -519,7 +519,7 @@ bool Storage::SetDefaultEntryValue(unsigned int local_id,
bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
if (name.empty()) return true;
if (!value) return true;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
Entry* entry = GetOrNew(name);
if (entry->value && entry->value->type() != value->type())
@@ -532,7 +532,7 @@ bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
bool Storage::SetEntryValue(unsigned int local_id,
std::shared_ptr<Value> value) {
if (!value) return true;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return true;
Entry* entry = m_localmap[local_id].get();
@@ -595,7 +595,7 @@ void Storage::SetEntryValueImpl(Entry* entry, std::shared_ptr<Value> value,
void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
if (name.empty()) return;
if (!value) return;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
Entry* entry = GetOrNew(name);
SetEntryValueImpl(entry, value, lock, true);
@@ -604,7 +604,7 @@ void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
void Storage::SetEntryTypeValue(unsigned int local_id,
std::shared_ptr<Value> value) {
if (!value) return;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return;
Entry* entry = m_localmap[local_id].get();
if (!entry) return;
@@ -614,14 +614,14 @@ void Storage::SetEntryTypeValue(unsigned int local_id,
void Storage::SetEntryFlags(StringRef name, unsigned int flags) {
if (name.empty()) return;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) return;
SetEntryFlagsImpl(i->getValue(), flags, lock, true);
}
void Storage::SetEntryFlags(unsigned int id_local, unsigned int flags) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (id_local >= m_localmap.size()) return;
SetEntryFlagsImpl(m_localmap[id_local].get(), flags, lock, true);
}
@@ -654,27 +654,27 @@ void Storage::SetEntryFlagsImpl(Entry* entry, unsigned int flags,
}
unsigned int Storage::GetEntryFlags(StringRef name) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) return 0;
return i->getValue()->flags;
}
unsigned int Storage::GetEntryFlags(unsigned int local_id) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
if (local_id >= m_localmap.size()) return 0;
return m_localmap[local_id]->flags;
}
void Storage::DeleteEntry(StringRef name) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
auto i = m_entries.find(name);
if (i == m_entries.end()) return;
DeleteEntryImpl(i->getValue(), lock, true);
}
void Storage::DeleteEntry(unsigned int local_id) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return;
DeleteEntryImpl(m_localmap[local_id].get(), lock, true);
}
@@ -745,7 +745,7 @@ void Storage::DeleteAllEntriesImpl(bool local) {
}
void Storage::DeleteAllEntries() {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_entries.empty()) return;
DeleteAllEntriesImpl(true);
@@ -773,7 +773,7 @@ unsigned int Storage::GetEntry(const Twine& name) {
if (name.isTriviallyEmpty() ||
(name.isSingleStringRef() && name.getSingleStringRef().empty()))
return UINT_MAX;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
return GetOrNew(name)->local_id;
}
@@ -781,7 +781,7 @@ std::vector<unsigned int> Storage::GetEntries(const Twine& prefix,
unsigned int types) {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
std::vector<unsigned int> ids;
for (auto& i : m_entries) {
Entry* entry = i.getValue();
@@ -800,7 +800,7 @@ EntryInfo Storage::GetEntryInfo(int inst, unsigned int local_id) const {
info.flags = 0;
info.last_change = 0;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return info;
Entry* entry = m_localmap[local_id].get();
if (!entry->value) return info;
@@ -814,13 +814,13 @@ EntryInfo Storage::GetEntryInfo(int inst, unsigned int local_id) const {
}
std::string Storage::GetEntryName(unsigned int local_id) const {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return std::string{};
return m_localmap[local_id]->name;
}
NT_Type Storage::GetEntryType(unsigned int local_id) const {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return NT_UNASSIGNED;
Entry* entry = m_localmap[local_id].get();
if (!entry->value) return NT_UNASSIGNED;
@@ -828,7 +828,7 @@ NT_Type Storage::GetEntryType(unsigned int local_id) const {
}
uint64_t Storage::GetEntryLastChange(unsigned int local_id) const {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return 0;
Entry* entry = m_localmap[local_id].get();
if (!entry->value) return 0;
@@ -839,7 +839,7 @@ std::vector<EntryInfo> Storage::GetEntryInfo(int inst, const Twine& prefix,
unsigned int types) {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
std::vector<EntryInfo> infos;
for (auto& i : m_entries) {
Entry* entry = i.getValue();
@@ -863,7 +863,7 @@ unsigned int Storage::AddListener(
unsigned int flags) const {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
unsigned int uid = m_notifier.Add(callback, prefixStr, flags);
// perform immediate notifications
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
@@ -881,7 +881,7 @@ unsigned int Storage::AddListener(
unsigned int local_id,
std::function<void(const EntryNotification& event)> callback,
unsigned int flags) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
unsigned int uid = m_notifier.Add(callback, local_id, flags);
// perform immediate notifications
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0 &&
@@ -900,7 +900,7 @@ unsigned int Storage::AddPolledListener(unsigned int poller,
unsigned int flags) const {
wpi::SmallString<128> prefixBuf;
StringRef prefixStr = prefix.toStringRef(prefixBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
unsigned int uid = m_notifier.AddPolled(poller, prefixStr, flags);
// perform immediate notifications
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
@@ -918,7 +918,7 @@ unsigned int Storage::AddPolledListener(unsigned int poller,
unsigned int Storage::AddPolledListener(unsigned int poller,
unsigned int local_id,
unsigned int flags) const {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
unsigned int uid = m_notifier.AddPolled(poller, local_id, flags);
// perform immediate notifications
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0 &&
@@ -939,7 +939,7 @@ bool Storage::GetPersistentEntries(
const {
// copy values out of storage as quickly as possible so lock isn't held
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
// for periodic, don't re-save unless something has changed
if (periodic && !m_persistent_dirty) return false;
m_persistent_dirty = false;
@@ -969,7 +969,7 @@ bool Storage::GetEntries(
StringRef prefixStr = prefix.toStringRef(prefixBuf);
// copy values out of storage as quickly as possible so lock isn't held
{
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
entries->reserve(m_entries.size());
for (auto& i : m_entries) {
Entry* entry = i.getValue();
@@ -990,7 +990,7 @@ bool Storage::GetEntries(
void Storage::CreateRpc(unsigned int local_id, StringRef def,
unsigned int rpc_uid) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return;
Entry* entry = m_localmap[local_id].get();
@@ -1028,7 +1028,7 @@ void Storage::CreateRpc(unsigned int local_id, StringRef def,
}
unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (local_id >= m_localmap.size()) return 0;
Entry* entry = m_localmap[local_id].get();
@@ -1055,7 +1055,7 @@ unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
unsigned int call_uid = msg->seq_num_uid();
m_rpc_server.ProcessRpc(local_id, call_uid, name, msg->str(), conn_info,
[=](StringRef result) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
m_rpc_results.insert(std::make_pair(
RpcIdPair{local_id, call_uid}, result));
m_rpc_results_cond.notify_all();
@@ -1078,7 +1078,7 @@ bool Storage::GetRpcResult(unsigned int local_id, unsigned int call_uid,
bool Storage::GetRpcResult(unsigned int local_id, unsigned int call_uid,
std::string* result, double timeout,
bool* timed_out) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
RpcIdPair call_pair{local_id, call_uid};
@@ -1124,7 +1124,7 @@ bool Storage::GetRpcResult(unsigned int local_id, unsigned int call_uid,
}
void Storage::CancelRpcResult(unsigned int local_id, unsigned int call_uid) {
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
// safe to erase even if id does not exist
m_rpc_blocking_calls.erase(RpcIdPair{local_id, call_uid});
m_rpc_results_cond.notify_all();

View File

@@ -370,7 +370,7 @@ bool Storage::LoadEntries(
// copy values into storage as quickly as possible so lock isn't held
std::vector<std::shared_ptr<Message>> msgs;
std::unique_lock<wpi::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
for (auto& i : entries) {
Entry* entry = GetOrNew(i.first);
auto old_value = entry->value;

View File

@@ -206,7 +206,7 @@ NetworkTableInstance NetworkTable::GetInstance() const {
NetworkTableEntry NetworkTable::GetEntry(const Twine& key) const {
wpi::SmallString<128> keyBuf;
StringRef keyStr = key.toStringRef(keyBuf);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
NT_Entry& entry = m_entries[keyStr];
if (entry == 0) {
entry = nt::GetEntry(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR) + keyStr);
@@ -259,7 +259,7 @@ void NetworkTable::AddTableListener(ITableListener* listener,
void NetworkTable::AddTableListenerEx(ITableListener* listener,
unsigned int flags) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
wpi::SmallString<128> path(m_path);
path += PATH_SEPARATOR_CHAR;
size_t prefix_len = path.size();
@@ -283,7 +283,7 @@ void NetworkTable::AddTableListener(StringRef key, ITableListener* listener,
void NetworkTable::AddTableListenerEx(StringRef key, ITableListener* listener,
unsigned int flags) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
size_t prefix_len = m_path.size() + 1;
auto entry = GetEntry(key);
NT_EntryListener id = nt::AddEntryListener(
@@ -336,7 +336,7 @@ void NetworkTable::RemoveTableListener(NT_EntryListener listener) {
void NetworkTable::AddSubTableListener(ITableListener* listener,
bool localNotify) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
size_t prefix_len = m_path.size() + 1;
// The lambda needs to be copyable, but StringMap is not, so use
@@ -362,7 +362,7 @@ void NetworkTable::AddSubTableListener(ITableListener* listener,
}
void NetworkTable::RemoveTableListener(ITableListener* listener) {
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
auto matches_begin =
std::remove_if(m_listeners.begin(), m_listeners.end(),
[=](const Listener& x) { return x.first == listener; });
@@ -397,7 +397,7 @@ std::vector<std::string> NetworkTable::GetKeys(int types) const {
std::vector<std::string> keys;
size_t prefix_len = m_path.size() + 1;
auto infos = GetEntryInfo(m_inst, m_path + Twine(PATH_SEPARATOR_CHAR), types);
std::lock_guard<wpi::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
for (auto& info : infos) {
auto relative_key = StringRef(info.name).substr(prefix_len);
if (relative_key.find(PATH_SEPARATOR_CHAR) != StringRef::npos) continue;

View File

@@ -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. */
@@ -959,7 +959,7 @@ void SetLogger(LogFunc func, unsigned int min_level) {
auto ii = InstanceImpl::GetDefault();
static wpi::mutex mutex;
static unsigned int logger = 0;
std::lock_guard<wpi::mutex> lock(mutex);
std::lock_guard lock(mutex);
if (logger != 0) ii->logger_impl.Remove(logger);
logger = ii->logger_impl.Add(
[=](const LogMessage& msg) {