Skip to content

Commit 427e9c9

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24069: refactor: replace RecursiveMutex m_cs_callbacks_pending with Mutex (and rename)
5574e6e refactor: replace RecursiveMutex `m_callbacks_mutex` with Mutex (Sebastian Falbesoner) 3aa2581 scripted-diff: rename `m_cs_callbacks_pending` -> `m_callbacks_mutex` (Sebastian Falbesoner) Pull request description: This PR is related to #19303 and gets rid of the RecursiveMutex `m_cs_callbacks_pending`. All of the critical sections (6 in total) only directly access the guarded elements, i.e. it is not possible that within one section another one is called, and we can use a regular Mutex: https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L138-L145 https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L152-L160 https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L169-L172 https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L184-L187 https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L197-L199 https://github.com/bitcoin/bitcoin/blob/807169e10b4a18324356ed6ee4d69587b96a7c70/src/scheduler.cpp#L203-L206 Also, it is renamed to adapt to the (unwritten) naming convention to use the `_mutex` suffix rather than the `cs_` prefix. ACKs for top commit: hebasto: ACK 5574e6e, I have reviewed the code and it looks OK, I agree it can be merged. w0xlt: crACK 5574e6e Tree-SHA512: ba4b151d956582f4c7183a1d51702b269158fc5e2902c51e6a242aaeb1c72cfcdf398f9ffa42e3072f5aba21a8c493086a5fe7c450c271322da69bd54c37ed1f
2 parents dbf81a7 + 5574e6e commit 427e9c9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/scheduler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool CScheduler::AreThreadsServicingQueue() const
136136
void SingleThreadedSchedulerClient::MaybeScheduleProcessQueue()
137137
{
138138
{
139-
LOCK(m_cs_callbacks_pending);
139+
LOCK(m_callbacks_mutex);
140140
// Try to avoid scheduling too many copies here, but if we
141141
// accidentally have two ProcessQueue's scheduled at once its
142142
// not a big deal.
@@ -150,7 +150,7 @@ void SingleThreadedSchedulerClient::ProcessQueue()
150150
{
151151
std::function<void()> callback;
152152
{
153-
LOCK(m_cs_callbacks_pending);
153+
LOCK(m_callbacks_mutex);
154154
if (m_are_callbacks_running) return;
155155
if (m_callbacks_pending.empty()) return;
156156
m_are_callbacks_running = true;
@@ -167,7 +167,7 @@ void SingleThreadedSchedulerClient::ProcessQueue()
167167
~RAIICallbacksRunning()
168168
{
169169
{
170-
LOCK(instance->m_cs_callbacks_pending);
170+
LOCK(instance->m_callbacks_mutex);
171171
instance->m_are_callbacks_running = false;
172172
}
173173
instance->MaybeScheduleProcessQueue();
@@ -182,7 +182,7 @@ void SingleThreadedSchedulerClient::AddToProcessQueue(std::function<void()> func
182182
assert(m_pscheduler);
183183

184184
{
185-
LOCK(m_cs_callbacks_pending);
185+
LOCK(m_callbacks_mutex);
186186
m_callbacks_pending.emplace_back(std::move(func));
187187
}
188188
MaybeScheduleProcessQueue();
@@ -194,13 +194,13 @@ void SingleThreadedSchedulerClient::EmptyQueue()
194194
bool should_continue = true;
195195
while (should_continue) {
196196
ProcessQueue();
197-
LOCK(m_cs_callbacks_pending);
197+
LOCK(m_callbacks_mutex);
198198
should_continue = !m_callbacks_pending.empty();
199199
}
200200
}
201201

202202
size_t SingleThreadedSchedulerClient::CallbacksPending()
203203
{
204-
LOCK(m_cs_callbacks_pending);
204+
LOCK(m_callbacks_mutex);
205205
return m_callbacks_pending.size();
206206
}

src/scheduler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ class SingleThreadedSchedulerClient
119119
private:
120120
CScheduler* m_pscheduler;
121121

122-
RecursiveMutex m_cs_callbacks_pending;
123-
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_cs_callbacks_pending);
124-
bool m_are_callbacks_running GUARDED_BY(m_cs_callbacks_pending) = false;
122+
Mutex m_callbacks_mutex;
123+
std::list<std::function<void()>> m_callbacks_pending GUARDED_BY(m_callbacks_mutex);
124+
bool m_are_callbacks_running GUARDED_BY(m_callbacks_mutex) = false;
125125

126126
void MaybeScheduleProcessQueue();
127127
void ProcessQueue();

0 commit comments

Comments
 (0)