Skip to content

Commit 1f96be2

Browse files
committed
Preserve initial state if push_lock() throws exception
1 parent a787428 commit 1f96be2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/sync.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,17 @@ static void push_lock(void* c, const CLockLocation& locklocation)
149149
const LockPair p1 = std::make_pair(i.first, c);
150150
if (lockdata.lockorders.count(p1))
151151
continue;
152-
lockdata.lockorders.emplace(p1, lock_stack);
153152

154153
const LockPair p2 = std::make_pair(c, i.first);
154+
if (lockdata.lockorders.count(p2)) {
155+
auto lock_stack_copy = lock_stack;
156+
lock_stack.pop_back();
157+
potential_deadlock_detected(p1, lockdata.lockorders[p2], lock_stack_copy);
158+
// potential_deadlock_detected() does not return.
159+
}
160+
161+
lockdata.lockorders.emplace(p1, lock_stack);
155162
lockdata.invlockorders.insert(p2);
156-
if (lockdata.lockorders.count(p2))
157-
potential_deadlock_detected(p1, lockdata.lockorders[p2], lockdata.lockorders[p1]);
158163
}
159164
}
160165

0 commit comments

Comments
 (0)