Skip to content

Commit 4d80277

Browse files
committed
Fix deadlock.
1 parent 470ff4f commit 4d80277

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSession.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,16 @@ void VideoSession::internal_set_resolution(Resolution resolution){
253253
}
254254

255255
void VideoSession::run_commands(){
256-
std::lock_guard<std::recursive_mutex> lg0(m_reset_lock);
257-
if (m_recursion_depth != 0){
256+
std::unique_lock<std::mutex> lg0(m_reset_lock, std::defer_lock);
257+
if (!lg0.try_lock()){
258258
m_logger.log("Suppressing re-entrant command...", COLOR_RED);
259259
return;
260260
}
261-
m_recursion_depth++;
262261
try{
263262
while (true){
264263
Command command;
265264
{
266-
WriteSpinLock lg(m_queue_lock);
265+
WriteSpinLock lg1(m_queue_lock);
267266
// cout << "VideoSession::run_commands(): " << m_queued_commands.size() << endl;
268267
if (m_queued_commands.empty()){
269268
break;
@@ -286,9 +285,7 @@ void VideoSession::run_commands(){
286285
break;
287286
}
288287
}
289-
m_recursion_depth--;
290288
}catch (...){
291-
m_recursion_depth--;
292289
throw;
293290
}
294291
}

SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSession.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class VideoSession
198198

199199

200200
private:
201-
mutable std::recursive_mutex m_reset_lock;
201+
mutable std::mutex m_reset_lock;
202202
mutable SpinLock m_state_lock;
203203
// bool m_shutting_down = false;
204204

@@ -215,7 +215,6 @@ class VideoSession
215215
// We need to queue up all reset commands and run them on the main thread.
216216
// This is needed to prevent re-entrant calls from event processing.
217217
SpinLock m_queue_lock;
218-
size_t m_recursion_depth = 0;
219218
std::deque<Command> m_queued_commands;
220219

221220
ListenerSet<StateListener> m_state_listeners;

0 commit comments

Comments
 (0)