|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_THREADING_BLOCKING_CONCURRENT_QUEUE_H_
2 #define GENESIS_UTILS_THREADING_BLOCKING_CONCURRENT_QUEUE_H_
74 #include <type_traits>
81 template <
typename T,
typename Traits = ConcurrentQueueDefaultTraits>
92 typedef typename std::make_signed<size_t>::type
ssize_t;
124 : inner(minCapacity, maxExplicitProducers, maxImplicitProducers)
144 : inner(std::move(other.inner)),
145 sema(std::move(other.sema))
151 return swap_internal(other);
161 swap_internal(other);
167 if (
this == &other) {
171 inner.
swap(other.inner);
172 sema.swap(other.sema);
237 template <
typename It>
253 template <
typename It>
322 template <
typename It>
337 template <
typename It>
351 template <
typename U>
354 if (sema->tryWait()) {
367 template <
typename U>
370 if (sema->tryWait()) {
384 template <
typename It>
389 while (count != max) {
390 count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
400 template <
typename It>
405 while (count != max) {
406 count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
414 template <
typename U>
417 while (!sema->wait()) {
432 template <
typename U>
435 if (!sema->wait(timeout_usecs)) {
448 template <
typename U,
typename Rep,
typename Period>
451 return wait_dequeue_timed(item, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
457 template <
typename U>
460 while (!sema->wait()) {
475 template <
typename U>
478 if (!sema->wait(timeout_usecs)) {
491 template <
typename U,
typename Rep,
typename Period>
494 return wait_dequeue_timed(token, item, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
502 template <
typename It>
507 while (count != max) {
508 count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
520 template <
typename It>
525 while (count != max) {
526 count += inner.template try_dequeue_bulk<It&>(itemFirst, max - count);
536 template <
typename It,
typename Rep,
typename Period>
539 return wait_dequeue_bulk_timed<It&>(itemFirst, max, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
547 template <
typename It>
552 while (count != max) {
553 count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
565 template <
typename It>
570 while (count != max) {
571 count += inner.template try_dequeue_bulk<It&>(token, itemFirst, max - count);
581 template <
typename It,
typename Rep,
typename Period>
584 return wait_dequeue_bulk_timed<It&>(token, itemFirst, max, std::chrono::duration_cast<std::chrono::microseconds>(timeout).count());
595 return (
size_t)sema->availableApprox();
607 template <
typename U,
typename A1,
typename A2>
608 static inline U* create(A1&& a1, A2&& a2)
610 void* p = (Traits::malloc)(
sizeof(U));
611 return p !=
nullptr ?
new (p) U(std::forward<A1>(a1), std::forward<A2>(a2)) :
nullptr;
614 template <
typename U>
615 static inline void destroy(U* p)
624 ConcurrentQueue inner;
625 std::unique_ptr<LightweightSemaphore, void (*)(LightweightSemaphore*)> sema;
628 template <
typename T,
typename Traits>
637 #endif // include guard
ConcurrentQueue::producer_token_t producer_token_t
static const size_t BLOCK_SIZE
#define MOODYCAMEL_NOEXCEPT
static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD
size_t wait_dequeue_bulk_timed(It itemFirst, size_t max, std::int64_t timeout_usecs)
bool wait_dequeue_timed(consumer_token_t &token, U &item, std::chrono::duration< Rep, Period > const &timeout)
void wait_dequeue(U &item)
bool try_enqueue_bulk(It itemFirst, size_t count)
bool enqueue(T const &item)
size_t wait_dequeue_bulk(It itemFirst, size_t max)
bool enqueue(producer_token_t const &token, T &&item)
bool enqueue_bulk(It itemFirst, size_t count)
bool try_enqueue_bulk(producer_token_t const &token, It itemFirst, size_t count)
static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE
bool try_dequeue(U &item)
#define MOODYCAMEL_DELETE_FUNCTION
bool try_enqueue(T const &item)
void wait_dequeue(consumer_token_t &token, U &item)
bool try_enqueue_bulk(It itemFirst, size_t count)
#define MOODYCAMEL_THROW(expr)
static constexpr bool is_lock_free()
ConcurrentQueue::size_t size_t
static constexpr bool is_lock_free()
bool try_enqueue(producer_token_t const &token, T const &item)
static const size_t EXPLICIT_INITIAL_INDEX_SIZE
static bool() likely(bool x)
static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD
ConcurrentQueueDefaultTraits ::index_t index_t
static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE
ConcurrentQueue::consumer_token_t consumer_token_t
bool enqueue_bulk(It itemFirst, size_t count)
void swap(Color &lhs, Color &rhs)
bool try_enqueue(T &&item)
bool try_dequeue(consumer_token_t &token, U &item)
BlockingConcurrentQueue & operator=(BlockingConcurrentQueue &&other) MOODYCAMEL_NOEXCEPT
size_t wait_dequeue_bulk_timed(It itemFirst, size_t max, std::chrono::duration< Rep, Period > const &timeout)
static const size_t EXPLICIT_INITIAL_INDEX_SIZE
size_t try_dequeue_bulk(consumer_token_t &token, It itemFirst, size_t max)
bool wait_dequeue_timed(U &item, std::chrono::duration< Rep, Period > const &timeout)
size_t wait_dequeue_bulk(consumer_token_t &token, It itemFirst, size_t max)
bool try_enqueue(T const &item)
std::make_signed< size_t >::type ssize_t
static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE
static const size_t MAX_SUBQUEUE_SIZE
ConcurrentQueueDefaultTraits ::size_t size_t
static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
size_t wait_dequeue_bulk_timed(consumer_token_t &token, It itemFirst, size_t max, std::int64_t timeout_usecs)
static const size_t IMPLICIT_INITIAL_INDEX_SIZE
bool wait_dequeue_timed(U &item, std::int64_t timeout_usecs)
static const size_t IMPLICIT_INITIAL_INDEX_SIZE
static const size_t BLOCK_SIZE
void swap(BlockingConcurrentQueue &other) MOODYCAMEL_NOEXCEPT
std::make_signed< std::size_t >::type ssize_t
BlockingConcurrentQueue(size_t capacity=6 *BLOCK_SIZE)
static const size_t MAX_SUBQUEUE_SIZE
bool try_enqueue(producer_token_t const &token, T &&item)
bool try_dequeue(U &item)
BlockingConcurrentQueue & operator=(BlockingConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION
bool enqueue(T const &item)
size_t wait_dequeue_bulk_timed(consumer_token_t &token, It itemFirst, size_t max, std::chrono::duration< Rep, Period > const &timeout)
bool enqueue(producer_token_t const &token, T const &item)
bool enqueue_bulk(producer_token_t const &token, It itemFirst, size_t count)
void swap(ConcurrentQueue &other) noexcept
size_t try_dequeue_bulk(It itemFirst, size_t max)
bool wait_dequeue_timed(consumer_token_t &token, U &item, std::int64_t timeout_usecs)
size_t size_approx() const
BlockingConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers)
BlockingConcurrentQueue(BlockingConcurrentQueue &&other) MOODYCAMEL_NOEXCEPT
ConcurrentQueue::index_t index_t