Skip to content

Commit

Permalink
don't hold onto lock while notifying
Browse files Browse the repository at this point in the history
Summary: This is a behavior-preserving change, making workqueues a bit faster.

Reviewed By: ssj933

Differential Revision: D49172863

fbshipit-source-id: 1445b40ac246f0e1b0f0f4f3b09fd2b142253081
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Sep 12, 2023
1 parent ca48b19 commit 1b6e972
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/sparta/WorkQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class Semaphore {
explicit Semaphore(size_t initial = 0u) : m_count(initial) {}

inline void give(size_t n = 1u) {
std::unique_lock<std::mutex> lock(m_mtx);
m_count += n;
{
std::lock_guard<std::mutex> lock(m_mtx);
m_count += n;
}
if (n == 1) {
m_cv.notify_one();
} else {
Expand All @@ -81,7 +83,7 @@ class Semaphore {
}

inline void take_all() {
std::unique_lock<std::mutex> lock(m_mtx);
std::lock_guard<std::mutex> lock(m_mtx);
m_count = 0;
}

Expand Down

0 comments on commit 1b6e972

Please sign in to comment.