Skip to content

Commit

Permalink
new(libsinsp): async event queue capacity setter
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian authored and poiana committed May 13, 2024
1 parent d3c804b commit e0fd864
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion userspace/libsinsp/mpsc_priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ class mpsc_priority_queue
}
}

/**
* @brief Sets the maximum capacity of the queue. Returns false
* if the the specified capacity cannot be set (when the current queue's
* size is bigger than the specified capacity).
* This setter doesn't actually set the capacity of 'm_queue',
* it sets 'm_capacity' which is the valued to used to bound the queue's
* size when pushing.
*/
inline bool set_capacity(size_t capacity)
{
std::scoped_lock<Mtx> lk(m_mtx);
if(m_queue.size() <= capacity)
{
m_capacity = capacity;
return true;
}

return false;
}

private:
using elm_ptr = typename Elm::element_type*;

Expand Down Expand Up @@ -185,7 +205,7 @@ class mpsc_priority_queue
uint64_t num;
};

const size_t m_capacity;
size_t m_capacity;
std::priority_queue<queue_elm> m_queue{};
std::atomic<elm_ptr> m_queue_top{nullptr};
std::atomic<uint64_t> m_elem_counter{0};
Expand Down

0 comments on commit e0fd864

Please sign in to comment.