Skip to content

Commit 531a1d4

Browse files
committed
Add labels to common deadlocked spinlocks.
1 parent bd3431c commit 531a1d4

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Common/Cpp/ListenerSet.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <exception>
1111
#include <map>
1212
#include <atomic>
13+
//#include "Common/Cpp/PrettyPrint.h"
1314
#include "Common/Cpp/Concurrency/SpinLock.h"
1415

1516
#include <iostream>
@@ -125,7 +126,7 @@ void ListenerSet<ListenerType>::add(ListenerType& listener){
125126
#ifdef PA_DEBUG_ListenerSet
126127
auto scope = m_sanitizer.check_scope();
127128
#endif
128-
WriteSpinLock lg(m_lock);
129+
WriteSpinLock lg(m_lock, "ListenerSet::add()");
129130
auto ret = m_listeners.emplace(
130131
std::piecewise_construct,
131132
std::forward_as_tuple(&listener),
@@ -154,7 +155,7 @@ void ListenerSet<ListenerType>::remove(ListenerType& listener) noexcept{
154155
bool printed = false;
155156

156157
while (true){
157-
WriteSpinLock lg(m_lock);
158+
WriteSpinLock lg(m_lock, "ListenerSet::remove()");
158159
auto iter = m_listeners.find(&listener);
159160
if (iter == m_listeners.end()){
160161
return;
@@ -260,7 +261,7 @@ void ListenerSet<ListenerType>::run_method(Function function, Args&&... args){
260261
Node* node = m_list;
261262
while (node){
262263
{
263-
ReadSpinLock lg(node->lock);
264+
ReadSpinLock lg(node->lock, "ListenerSet::run_method()");
264265

265266
#ifdef PA_DEBUG_ListenerSet
266267
node->sanitizer.check_usage();

SerialPrograms/Source/Controllers/SerialPABotBase/Connection/PABotBase.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void PABotBase::stop(std::string error_message){
100100
}
101101

102102
if (!error_message.empty()){
103-
ReadSpinLock lg(m_state_lock);
103+
ReadSpinLock lg(m_state_lock, "PABotBase::stop()");
104104
m_error_message = std::move(error_message);
105105
}
106106

@@ -155,15 +155,15 @@ void PABotBase::wait_for_all_requests(Cancellable* cancelled){
155155
cancelled->throw_if_cancelled();
156156
}
157157
if (m_state.load(std::memory_order_acquire) != State::RUNNING){
158-
ReadSpinLock lg0(m_state_lock);
158+
ReadSpinLock lg0(m_state_lock, "PABotBase::wait_for_all_requests() - 0");
159159
throw InvalidConnectionStateException(m_error_message);
160160
}
161161
if (m_error.load(std::memory_order_acquire)){
162-
ReadSpinLock lg0(m_state_lock);
162+
ReadSpinLock lg0(m_state_lock, "PABotBase::wait_for_all_requests() - 1");
163163
throw ConnectionException(&m_logger, m_error_message);
164164
}
165165
{
166-
ReadSpinLock lg1(m_state_lock, "PABotBase::wait_for_all_requests()");
166+
ReadSpinLock lg1(m_state_lock, "PABotBase::wait_for_all_requests() - 2");
167167
#if 0
168168
m_logger.log(
169169
"Waiting for all requests to finish... (Requests: " +
@@ -434,7 +434,7 @@ void PABotBase::process_command_finished(BotBaseMessage message){
434434

435435
{
436436
std::lock_guard<std::mutex> lg0(m_sleep_lock);
437-
WriteSpinLock lg1(m_state_lock, "PABotBase::process_command_finished() - 0");
437+
WriteSpinLock lg1(m_state_lock, "PABotBase::process_command_finished()");
438438

439439
#ifdef INTENTIONALLY_DROP_MESSAGES
440440
if (rand() % 10 != 0){
@@ -510,7 +510,7 @@ void PABotBase::on_recv_message(BotBaseMessage message){
510510
}
511511
const pabb_MsgInfoInvalidType* params = (const pabb_MsgInfoInvalidType*)message.body.c_str();
512512
{
513-
WriteSpinLock lg(m_state_lock);
513+
WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() - 0");
514514
m_error_message = "PABotBase incompatibility. Device does not recognize message type: " + std::to_string(params->type);
515515
m_logger.log(m_error_message, COLOR_RED);
516516
}
@@ -528,7 +528,7 @@ void PABotBase::on_recv_message(BotBaseMessage message){
528528
const pabb_MsgInfoMissedRequest* params = (const pabb_MsgInfoMissedRequest*)message.body.c_str();
529529
if (params->seqnum == 1){
530530
{
531-
WriteSpinLock lg(m_state_lock);
531+
WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() = 1");
532532
m_error_message = "Serial connection has been interrupted.";
533533
m_logger.log(m_error_message, COLOR_RED);
534534
}
@@ -543,7 +543,7 @@ void PABotBase::on_recv_message(BotBaseMessage message){
543543
case PABB_MSG_ERROR_DISCONNECTED:{
544544
m_logger.log("The console has disconnected the controller.", COLOR_RED);
545545
{
546-
WriteSpinLock lg(m_state_lock);
546+
WriteSpinLock lg(m_state_lock, "PABotBase::on_recv_message() - 2");
547547
m_error_message = "Disconnected by console.";
548548
}
549549
m_error.store(true, std::memory_order_release);
@@ -839,11 +839,11 @@ uint64_t PABotBase::issue_request(
839839
cancelled->throw_if_cancelled();
840840
}
841841
if (m_state.load(std::memory_order_acquire) != State::RUNNING){
842-
ReadSpinLock lg0(m_state_lock);
842+
ReadSpinLock lg0(m_state_lock, "PABotBase::issue_request() - 0");
843843
throw InvalidConnectionStateException(m_error_message);
844844
}
845845
if (m_error.load(std::memory_order_acquire)){
846-
ReadSpinLock lg0(m_state_lock);
846+
ReadSpinLock lg0(m_state_lock, "PABotBase::issue_request() - 1");
847847
throw ConnectionException(&m_logger, m_error_message);
848848
}
849849
cv_wait(cancelled, lg);
@@ -884,11 +884,11 @@ uint64_t PABotBase::issue_command(
884884
cancelled->throw_if_cancelled();
885885
}
886886
if (m_state.load(std::memory_order_acquire) != State::RUNNING){
887-
ReadSpinLock lg0(m_state_lock);
887+
ReadSpinLock lg0(m_state_lock, "PABotBase::issue_command() - 0");
888888
throw InvalidConnectionStateException(m_error_message);
889889
}
890890
if (m_error.load(std::memory_order_acquire)){
891-
ReadSpinLock lg0(m_state_lock);
891+
ReadSpinLock lg0(m_state_lock, "PABotBase::issue_command() - 1");
892892
throw ConnectionException(&m_logger, m_error_message);
893893
}
894894
cv_wait(cancelled, lg);

0 commit comments

Comments
 (0)