Skip to content

Commit

Permalink
ThreadPoolExecutor: Drop std::binary_semaphore polyfill. (#3317)
Browse files Browse the repository at this point in the history
All targets we compile for should now support enough C++20 stdlib
features to remove the need for us to provide a fallback.
  • Loading branch information
AlanGriffiths authored Apr 8, 2024
2 parents f80f726 + d36c200 commit a8f5b20
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions src/common/thread_pool_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,7 @@
#include <atomic>
#include <list>
#include <future>

#include <version>

#ifdef __cpp_lib_semaphore
#include <semaphore>
#else
// Hello, there! This version of libstdc++ doesn't support the C++20 feature std::binary_semaphore
// We shall, instead, open-code the simplest possible implementation of what we use here.
namespace std
{
class binary_semaphore
{
public:
binary_semaphore(int initial)
: raised{initial == 1}
{
}

void release()
{
{
std::lock_guard lock{mutex};
raised = true;
}
cv.notify_all();
}

void acquire()
{
std::unique_lock lock{mutex};
if (raised)
{
raised = false;
return;
}
cv.wait(lock, [this]() { return raised; });
raised = false;
}

bool try_acquire()
{
std::lock_guard lock{mutex};
if (raised)
{
raised = false;
return true;
}
return false;
}
private:
std::mutex mutex;
std::condition_variable cv;
bool raised;
};
}
#endif

namespace
{
Expand Down

0 comments on commit a8f5b20

Please sign in to comment.