Remove capacity safeties.

This commit is contained in:
Bartosz Taudul 2021-11-14 18:52:57 +01:00
parent 5306034893
commit a5f5dcc00f
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -37,16 +37,7 @@ template <typename T> class SPSCQueue {
public: public:
explicit SPSCQueue(const size_t capacity) explicit SPSCQueue(const size_t capacity)
: capacity_(capacity) { : capacity_(capacity) {
// The queue needs at least one element
if (capacity_ < 1) {
capacity_ = 1;
}
capacity_++; // Needs one slack element capacity_++; // Needs one slack element
// Prevent overflowing size_t
if (capacity_ > SIZE_MAX - 2 * kPadding) {
capacity_ = SIZE_MAX - 2 * kPadding;
}
slots_ = (T*)tracy_malloc(sizeof(T) * (capacity_ + 2 * kPadding)); slots_ = (T*)tracy_malloc(sizeof(T) * (capacity_ + 2 * kPadding));
static_assert(alignof(SPSCQueue<T>) == kCacheLineSize, ""); static_assert(alignof(SPSCQueue<T>) == kCacheLineSize, "");