Skip to content

Commit

Permalink
cap capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Apr 17, 2023
1 parent 0e6285c commit 57f8104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion quill/include/quill/detail/spsc_queue/UnboundedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class UnboundedQueue
}

// bounded queue max power of 2 capacity since uint32_t type is used to hold the value 2147483648 bytes
constexpr uint64_t max_bounded_queue_capacity = (std::numeric_limits<uint32_t>::max() >> 1) + 1;
constexpr uint64_t max_bounded_queue_capacity =
(std::numeric_limits<BoundedQueue::integer_type>::max() >> 1) + 1;

if (QUILL_UNLIKELY(capacity > max_bounded_queue_capacity))
{
if ((nbytes + 1) > max_bounded_queue_capacity)
Expand Down
7 changes: 5 additions & 2 deletions quill/src/detail/backend/TransitEventBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ TransitEvent* UnboundedTransitEventBuffer::back() noexcept
{
// buffer doesn't have enough space
uint64_t capacity = static_cast<uint64_t>(_writer->transit_buffer.capacity()) * 2ull;
if (QUILL_UNLIKELY(capacity > std::numeric_limits<uint32_t>::max()))
constexpr uint64_t max_bounded_queue_capacity =
(std::numeric_limits<BoundedTransitEventBuffer::integer_type>::max() >> 1) + 1;

if (QUILL_UNLIKELY(capacity > max_bounded_queue_capacity))
{
capacity = std::numeric_limits<uint32_t>::max();
capacity = max_bounded_queue_capacity;
}

auto new_node = new Node{static_cast<uint32_t>(capacity)};
Expand Down

0 comments on commit 57f8104

Please sign in to comment.