Updated atomic_queue
This commit is contained in:
parent
501dd60d2b
commit
4e5893c048
3 changed files with 15 additions and 36 deletions
47
src/external/atomic_queue/atomic_queue.h
vendored
47
src/external/atomic_queue/atomic_queue.h
vendored
|
|
@ -28,34 +28,13 @@ namespace details {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<size_t elements_per_cache_line>
|
template<size_t elements_per_cache_line> struct GetCacheLineIndexBits { static int constexpr value = 0; };
|
||||||
struct GetCacheLineIndexBits {
|
template<> struct GetCacheLineIndexBits<64> { static int constexpr value = 6; };
|
||||||
static int constexpr value = 0;
|
template<> struct GetCacheLineIndexBits<32> { static int constexpr value = 5; };
|
||||||
};
|
template<> struct GetCacheLineIndexBits<16> { static int constexpr value = 4; };
|
||||||
template<>
|
template<> struct GetCacheLineIndexBits< 8> { static int constexpr value = 3; };
|
||||||
struct GetCacheLineIndexBits<64> {
|
template<> struct GetCacheLineIndexBits< 4> { static int constexpr value = 2; };
|
||||||
static int constexpr value = 6;
|
template<> struct GetCacheLineIndexBits< 2> { static int constexpr value = 1; };
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct GetCacheLineIndexBits<32> {
|
|
||||||
static int constexpr value = 5;
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct GetCacheLineIndexBits<16> {
|
|
||||||
static int constexpr value = 4;
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct GetCacheLineIndexBits<8> {
|
|
||||||
static int constexpr value = 3;
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct GetCacheLineIndexBits<4> {
|
|
||||||
static int constexpr value = 2;
|
|
||||||
};
|
|
||||||
template<>
|
|
||||||
struct GetCacheLineIndexBits<2> {
|
|
||||||
static int constexpr value = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<bool minimize_contention, unsigned array_size, size_t elements_per_cache_line>
|
template<bool minimize_contention, unsigned array_size, size_t elements_per_cache_line>
|
||||||
struct GetIndexShuffleBits {
|
struct GetIndexShuffleBits {
|
||||||
|
|
@ -321,7 +300,7 @@ public:
|
||||||
static_cast<Derived&>(*this).do_push(std::forward<T>(element), head);
|
static_cast<Derived&>(*this).do_push(std::forward<T>(element), head);
|
||||||
}
|
}
|
||||||
|
|
||||||
Derived& pop() noexcept {
|
Derived pop() noexcept {
|
||||||
unsigned tail;
|
unsigned tail;
|
||||||
if(Derived::spsc_) {
|
if(Derived::spsc_) {
|
||||||
tail = tail_.load(X);
|
tail = tail_.load(X);
|
||||||
|
|
@ -342,7 +321,7 @@ public:
|
||||||
return static_cast<int>(head_.load(X) - tail_.load(X)) >= static_cast<int>(static_cast<Derived const&>(*this).size_);
|
return static_cast<int>(head_.load(X) - tail_.load(X)) >= static_cast<int>(static_cast<Derived const&>(*this).size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned size() const noexcept {
|
unsigned capacity() const noexcept {
|
||||||
return static_cast<Derived const&>(*this).size_;
|
return static_cast<Derived const&>(*this).size_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -491,7 +470,7 @@ public:
|
||||||
|
|
||||||
void swap(AtomicQueueB& b) noexcept {
|
void swap(AtomicQueueB& b) noexcept {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(static_cast<Base&>(*this), static_cast<Base&>(b));
|
this->Base::swap(b);
|
||||||
swap(static_cast<AllocatorElements&>(*this), static_cast<AllocatorElements&>(b));
|
swap(static_cast<AllocatorElements&>(*this), static_cast<AllocatorElements&>(b));
|
||||||
swap(size_, b.size_);
|
swap(size_, b.size_);
|
||||||
swap(elements_, b.elements_);
|
swap(elements_, b.elements_);
|
||||||
|
|
@ -532,13 +511,13 @@ class AtomicQueueB2 : public AtomicQueueCommon<AtomicQueueB2<T, A, MAXIMIZE_THRO
|
||||||
static_assert(SHUFFLE_BITS, "Unexpected SHUFFLE_BITS.");
|
static_assert(SHUFFLE_BITS, "Unexpected SHUFFLE_BITS.");
|
||||||
|
|
||||||
T do_pop(unsigned tail) noexcept {
|
T do_pop(unsigned tail) noexcept {
|
||||||
unsigned index = details::remap_index<SHUFFLE_BITS>(tail % (size_ - 1));
|
unsigned index = details::remap_index<SHUFFLE_BITS>(tail & (size_ - 1));
|
||||||
return Base::template do_pop_any(states_[index], elements_[index]);
|
return Base::template do_pop_any(states_[index], elements_[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
void do_push(U&& element, unsigned head) noexcept {
|
void do_push(U&& element, unsigned head) noexcept {
|
||||||
unsigned index = details::remap_index<SHUFFLE_BITS>(head % (size_ - 1));
|
unsigned index = details::remap_index<SHUFFLE_BITS>(head & (size_ - 1));
|
||||||
Base::template do_push_any(std::forward<U>(element), states_[index], elements_[index]);
|
Base::template do_push_any(std::forward<U>(element), states_[index], elements_[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -588,7 +567,7 @@ public:
|
||||||
|
|
||||||
void swap(AtomicQueueB2& b) noexcept {
|
void swap(AtomicQueueB2& b) noexcept {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(static_cast<Base&>(*this), static_cast<Base&>(b));
|
this->Base::swap(b);
|
||||||
swap(static_cast<AllocatorElements&>(*this), static_cast<AllocatorElements&>(b));
|
swap(static_cast<AllocatorElements&>(*this), static_cast<AllocatorElements&>(b));
|
||||||
swap(static_cast<AllocatorStates&>(*this), static_cast<AllocatorStates&>(b));
|
swap(static_cast<AllocatorStates&>(*this), static_cast<AllocatorStates&>(b));
|
||||||
swap(size_, b.size_);
|
swap(size_, b.size_);
|
||||||
|
|
|
||||||
2
src/external/atomic_queue/defs.h
vendored
2
src/external/atomic_queue/defs.h
vendored
|
|
@ -45,7 +45,7 @@ static inline void spin_loop_pause() noexcept {
|
||||||
|
|
||||||
namespace atomic_queue {
|
namespace atomic_queue {
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define ATOMIC_QUEUE_LIKELY(expr) __builtin_expect(static_cast<bool>(expr), 1)
|
#define ATOMIC_QUEUE_LIKELY(expr) __builtin_expect(static_cast<bool>(expr), 1)
|
||||||
#define ATOMIC_QUEUE_UNLIKELY(expr) __builtin_expect(static_cast<bool>(expr), 0)
|
#define ATOMIC_QUEUE_UNLIKELY(expr) __builtin_expect(static_cast<bool>(expr), 0)
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ sfz::FilePromisePtr sfz::FilePool::getFilePromise(const std::string& filename) n
|
||||||
promise->creationTime = std::chrono::high_resolution_clock::now();
|
promise->creationTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
if (!promiseQueue.try_push(promise)) {
|
if (!promiseQueue.try_push(promise)) {
|
||||||
DBG("[sfizz] Could not enqueue the promise for " << filename << " (queue size " << promiseQueue.size() << ")");
|
DBG("[sfizz] Could not enqueue the promise for " << filename << " (queue capacity " << promiseQueue.capacity() << ")");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue