mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Tools: Add a copyable SharedSemaphore
This commit is contained in:
committed by
Dennis Klein
parent
0e5f648d2b
commit
5d6184cd1a
@@ -45,6 +45,29 @@ auto Semaphore::GetCount() -> std::size_t
|
|||||||
return fCount;
|
return fCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SharedSemaphore::SharedSemaphore()
|
||||||
|
: fSemaphore(std::make_shared<Semaphore>())
|
||||||
|
{}
|
||||||
|
|
||||||
|
SharedSemaphore::SharedSemaphore(std::size_t initial_count)
|
||||||
|
: fSemaphore(std::make_shared<Semaphore>(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 tools */
|
||||||
} /* namespace mq */
|
} /* namespace mq */
|
||||||
} /* namespace fair */
|
} /* namespace fair */
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace fair {
|
namespace fair {
|
||||||
@@ -24,7 +25,7 @@ namespace tools {
|
|||||||
*/
|
*/
|
||||||
struct Semaphore
|
struct Semaphore
|
||||||
{
|
{
|
||||||
explicit Semaphore();
|
Semaphore();
|
||||||
explicit Semaphore(std::size_t initial_count);
|
explicit Semaphore(std::size_t initial_count);
|
||||||
|
|
||||||
auto Wait() -> void;
|
auto Wait() -> void;
|
||||||
@@ -37,6 +38,23 @@ private:
|
|||||||
std::condition_variable fCv;
|
std::condition_variable fCv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct SharedSemaphore Semaphore.h <fairmq/tools/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<Semaphore> fSemaphore;
|
||||||
|
};
|
||||||
|
|
||||||
} /* namespace tools */
|
} /* namespace tools */
|
||||||
} /* namespace mq */
|
} /* namespace mq */
|
||||||
} /* namespace fair */
|
} /* namespace fair */
|
||||||
|
Reference in New Issue
Block a user