diff --git a/fairmq/tools/Semaphore.cxx b/fairmq/tools/Semaphore.cxx index d60f4fe1..0d2018fb 100644 --- a/fairmq/tools/Semaphore.cxx +++ b/fairmq/tools/Semaphore.cxx @@ -45,6 +45,29 @@ auto Semaphore::GetCount() -> std::size_t return fCount; } +SharedSemaphore::SharedSemaphore() + : fSemaphore(std::make_shared()) +{} + +SharedSemaphore::SharedSemaphore(std::size_t initial_count) + : fSemaphore(std::make_shared(initial_count)) +{} + +auto SharedSemaphore::Wait() -> void +{ + fSemaphore->Wait(); +} + +auto SharedSemaphore::Signal() -> void +{ + fSemaphore->Signal(); +} + +auto SharedSemaphore::GetCount() -> std::size_t +{ + return fSemaphore->GetCount(); +} + } /* namespace tools */ } /* namespace mq */ } /* namespace fair */ diff --git a/fairmq/tools/Semaphore.h b/fairmq/tools/Semaphore.h index 09f97412..ab36ff9f 100644 --- a/fairmq/tools/Semaphore.h +++ b/fairmq/tools/Semaphore.h @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace fair { @@ -24,7 +25,7 @@ namespace tools { */ struct Semaphore { - explicit Semaphore(); + Semaphore(); explicit Semaphore(std::size_t initial_count); auto Wait() -> void; @@ -37,6 +38,23 @@ private: std::condition_variable fCv; }; +/** + * @struct SharedSemaphore Semaphore.h + * @brief A simple copyable blocking semaphore. + */ +struct SharedSemaphore +{ + SharedSemaphore(); + explicit SharedSemaphore(std::size_t initial_count); + + auto Wait() -> void; + auto Signal() -> void; + auto GetCount() -> std::size_t; + +private: + std::shared_ptr fSemaphore; +}; + } /* namespace tools */ } /* namespace mq */ } /* namespace fair */