Commit 10d27fea authored by Cornel Rat's avatar Cornel Rat Committed by Facebook Github Bot

Remove recursion from TimedMutex to avoid fiber stack overflows

Summary: Under heavy contention, lock will recurse several times. This can lead to fiber stack overflow.

Differential Revision: D14936384

fbshipit-source-id: e934569a9f742859655ba3ea888ebabd4d959651
parent 231d1cff
...@@ -79,16 +79,15 @@ TimedMutex::LockResult TimedMutex::lockHelper(WaitFunc&& waitFunc) { ...@@ -79,16 +79,15 @@ TimedMutex::LockResult TimedMutex::lockHelper(WaitFunc&& waitFunc) {
} }
inline void TimedMutex::lock() { inline void TimedMutex::lock() {
auto result = lockHelper([](MutexWaiter& waiter) { LockResult result;
waiter.baton.wait(); do {
return true; result = lockHelper([](MutexWaiter& waiter) {
}); waiter.baton.wait();
return true;
});
DCHECK(result != LockResult::TIMEOUT); DCHECK(result != LockResult::TIMEOUT);
if (result == LockResult::SUCCESS) { } while (result != LockResult::SUCCESS);
return;
}
lock();
} }
template <typename Rep, typename Period> template <typename Rep, typename Period>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment