本文整理汇总了C++中queue_type::size方法的典型用法代码示例。如果您正苦于以下问题:C++ queue_type::size方法的具体用法?C++ queue_type::size怎么用?C++ queue_type::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue_type
的用法示例。
在下文中一共展示了queue_type::size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enqueue
//! Enqueues log record to the queue
void enqueue(record_view const& rec)
{
unique_lock< mutex_type > lock(m_mutex);
std::size_t size = m_queue.size();
for (; size >= MaxQueueSizeV; size = m_queue.size())
{
if (!overflow_strategy::on_overflow(rec, lock))
return;
}
m_queue.push(rec);
if (size == 0)
m_cond.notify_one();
}
示例2: enqueue_conditional_signal
inline void enqueue_conditional_signal(const T& elem, size_t signal_at_size) {
m_mutex.lock();
m_queue.push_back(elem);
// Signal threads waiting on the queue
if (sleeping && m_queue.size() >= signal_at_size) m_conditional.signal();
m_mutex.unlock();
}
示例3: return
//! Equality operator.
bool operator==(const iterator& it)const {
if (m_queue.size() != it.m_queue.size()) { // if the queue size is different
return false; // the state of the to iterator are different
}
if (m_queue.empty()) { // if the queue is empty, we have to check if they are valid and
return it.m_valid == m_valid and it.m_cst == m_cst; // belong to the same cst
}
return (it.m_valid == m_valid) // valid status is equal => for end() iterator
and (it.m_cst == m_cst) // iterator belongs to the same cst
and (it.m_queue.front() == m_queue.front()) // front element and
and (it.m_queue.back() == m_queue.back()); // back element are the same.
}
示例4: try_dequeue
//! Attempts to dequeue log record from the queue, does not block if the queue is empty
bool try_dequeue(record_view& rec)
{
lock_guard< mutex_type > lock(m_mutex);
const std::size_t size = m_queue.size();
if (size > 0)
{
rec.swap(m_queue.front());
m_queue.pop();
if (size == MaxQueueSizeV)
overflow_strategy::on_queue_space_available();
return true;
}
return false;
}
示例5: test_pop
void test_pop()
{
size_t num = 10, count = 0;
fill(num);
while (!m_queue.empty())
m_queue.pop();
ASSERT_EQ(0, m_queue.size());
for (auto i : m_queue)
count++;
ASSERT_EQ(0, count);
clear();
}
示例6: dequeue
bool dequeue( msg_type & msg, boost::xtime const& xt)
{
typename boost::mutex::scoped_lock lock( mtx_);
if ( active_ == false && empty_() ) return false;
not_empty_cond_.timed_wait(
lock,
xt,
boost::bind(
& Queue< T, Q >::consumers_activate_,
this) );
if ( empty_() )
msg.reset();
else
dequeue_( msg);
if ( active_ == true && queue_.size() <= low_water_mark_)
not_full_cond_.notify_one();
return msg ? true : false;
}
示例7: try_timed_wait_for_data
/// Returns immediately of queue size is >= immedeiate_size
/// Otherwise, it will poll over 'ns' nanoseconds or on a signal
/// until queue is not empty.
inline bool try_timed_wait_for_data(size_t ns, size_t immediate_size) {
m_mutex.lock();
bool success = false;
// Wait while the queue is empty and this queue is alive
if (m_queue.size() < immediate_size) {
if (m_queue.empty() && m_alive) {
sleeping++;
m_conditional.timedwait_ns(m_mutex, ns);
sleeping--;
}
}
// An element has been added or a signal was raised
if(!m_queue.empty()) {
success = true;
}
m_mutex.unlock();
return success;
}
示例8: try_enqueue
//! Attempts to enqueue log record to the queue
bool try_enqueue(record_view const& rec)
{
unique_lock< mutex_type > lock(m_mutex, try_to_lock);
if (lock.owns_lock())
{
const std::size_t size = m_queue.size();
// Do not invoke the bounding strategy in case of overflow as it may block
if (size < MaxQueueSizeV)
{
m_queue.push(rec);
if (size == 0)
m_cond.notify_one();
return true;
}
}
return false;
}
示例9: dequeue_ready
//! Dequeues log record from the queue, blocks if the queue is empty
bool dequeue_ready(record_view& rec)
{
unique_lock< mutex_type > lock(m_mutex);
while (!m_interruption_requested)
{
const std::size_t size = m_queue.size();
if (size > 0)
{
rec.swap(m_queue.front());
m_queue.pop();
if (size == MaxQueueSizeV)
overflow_strategy::on_queue_space_available();
return true;
}
else
{
m_cond.wait(lock);
}
}
m_interruption_requested = false;
return false;
}
示例10: size
//! Returns the current number of nodes in the queue.
size_type size() const { return m_queue.size(); }
示例11: full_
bool full_() const
{
if ( high_water_mark_ == infinity_) return false;
return queue_.size() > high_water_mark_;
}
示例12: size
std::size_t size() const{
return queue_.size();
}
示例13: size
//! get the current size of the queue
inline size_t size() {
return m_queue.size();
}
示例14: size
std::size_t size(unsigned int timeout = 5) {
boost::shared_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(timeout));
if (!lock || queue_.empty())
return 0;
return queue_.size();
}