Skip to content

Commit

Permalink
Default template parameter for SaturatingSemaphore<>
Browse files Browse the repository at this point in the history
Summary:
Blocking should be the default behavior, the spinning behavior is only for niche cases and it should not be encouraged. `Baton<>` already does this.

No functional changes, only remove the argument when redundant.

Reviewed By: Gownta

Differential Revision: D49233637

fbshipit-source-id: c69a3bba2cccee9c114db0b2e1243ee122e278f5
  • Loading branch information
ot authored and facebook-github-bot committed Sep 14, 2023
1 parent d85a0f6 commit 30a1823
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion folly/executors/test/GlobalExecutorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ TEST(GlobalExecutorTest, GetGlobalCPUExecutorCounters) {
const size_t numThreads = getGlobalCPUExecutorCounters().numThreads;
const size_t numTasks = 1000 + numThreads;
// Makes all tasks block until we're done.
folly::SaturatingSemaphore</* MayBlock */ true> block;
folly::SaturatingSemaphore<> block;
// Ensures that the semaphore is alive until all tasks have run.
folly::VirtualExecutor ex(getGlobalCPUExecutor());
for (size_t i = 0; i < numTasks; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion folly/futures/HeapTimekeeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HeapTimekeeper : public Timekeeper {

private:
using Clock = std::chrono::steady_clock;
using Semaphore = SaturatingSemaphore</* MayBlock */ true>;
using Semaphore = SaturatingSemaphore<>;

static constexpr size_t kQueueBatchSize = 256;
// Queue capacity is kept in this band to make sure that it is reallocated
Expand Down
2 changes: 1 addition & 1 deletion folly/synchronization/Latch.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Latch {
}

std::atomic<int32_t> count_;
SaturatingSemaphore</* MayBlock = */ true> semaphore_;
SaturatingSemaphore<> semaphore_;
};

} // namespace folly
4 changes: 2 additions & 2 deletions folly/synchronization/SaturatingSemaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace folly {
///
/// Usage:
/// @code
/// SaturatingSemaphore</* MayBlock = */ true> f;
/// SaturatingSemaphore<> f;
/// ASSERT_FALSE(f.try_wait());
/// ASSERT_FALSE(f.try_wait_until(
/// std::chrono::steady_clock::now() + std::chrono::microseconds(1)));
Expand All @@ -117,7 +117,7 @@ namespace folly {
/// ASSERT_FALSE(f.try_wait());
/// @endcode

template <bool MayBlock, template <typename> class Atom = std::atomic>
template <bool MayBlock = true, template <typename> class Atom = std::atomic>
class SaturatingSemaphore {
detail::Futex<Atom> state_;

Expand Down
2 changes: 1 addition & 1 deletion folly/synchronization/ThrottledLifoSem.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ThrottledLifoSem {
friend class ThrottledLifoSemTestHelper;

struct Waiter {
SaturatingSemaphore</* MayBlock */ true> wakeup;
SaturatingSemaphore<> wakeup;
SafeIntrusiveListHook hook;
};

Expand Down
2 changes: 1 addition & 1 deletion folly/synchronization/test/ThrottledLifoSemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ TEST(ThrottledLifoSem, MPMCStress) {

std::vector<std::thread> producers;
std::vector<std::thread> consumers;
folly::SaturatingSemaphore</* MayBlock */ true> done;
folly::SaturatingSemaphore<> done;
std::atomic<size_t> handoffs = 0;
for (size_t t = 0; t < kNumThreads; ++t) {
producers.emplace_back([&] {
Expand Down

0 comments on commit 30a1823

Please sign in to comment.