本文整理汇总了C++中queue_type::top方法的典型用法代码示例。如果您正苦于以下问题:C++ queue_type::top方法的具体用法?C++ queue_type::top怎么用?C++ queue_type::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue_type
的用法示例。
在下文中一共展示了queue_type::top方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_top
void test_top()
{
std::array<int, 10> priorities = {0,1,2,3,2,1,0,1,2,0};
for (auto i : priorities)
m_queue.push(i, i);
for (size_t i = 0; i < priorities.size(); ++i) {
ASSERT_LE(m_queue.top(), m_last_priority);
m_last_priority = m_queue.top();
m_queue.pop();
}
clear();
m_last_priority = m_max_priority;
}
示例2: dequeue_ready
//! Dequeues log record from the queue, blocks if no log records are ready to be processed
bool dequeue_ready(record_view& rec)
{
unique_lock< mutex_type > lock(m_mutex);
while (!m_interruption_requested)
{
if (!m_queue.empty())
{
const boost::log::aux::timestamp now = boost::log::aux::get_timestamp();
enqueued_record const& elem = m_queue.top();
const uint64_t difference = (now - elem.m_timestamp).milliseconds();
if (difference >= m_ordering_window)
{
// We got a new element
rec = elem.m_record;
m_queue.pop();
return true;
}
else
{
// Wait until the element becomes ready to be processed
m_cond.timed_wait(lock, posix_time::milliseconds(m_ordering_window - difference));
}
}
else
{
// Wait for an element to come
m_cond.wait(lock);
}
}
m_interruption_requested = false;
return false;
}
示例3: try_take_
bool try_take_( callable & ca)
{
if ( empty_() )
return false;
callable tmp( queue_.top().ca);
queue_.pop();
ca.swap( tmp);
return ! ca.empty();
}
示例4: try_dequeue
//! Attempts to dequeue log record from the queue, does not block.
bool try_dequeue(record_view& rec)
{
lock_guard< mutex_type > lock(m_mutex);
if (!m_queue.empty())
{
enqueued_record const& elem = m_queue.top();
rec = elem.m_record;
m_queue.pop();
return true;
}
return false;
}
示例5: try_dequeue_ready
//! Attempts to dequeue a log record ready for processing from the queue, does not block if no log records are ready to be processed
bool try_dequeue_ready(record_view& rec)
{
lock_guard< mutex_type > lock(m_mutex);
if (!m_queue.empty())
{
const boost::log::aux::timestamp now = boost::log::aux::get_timestamp();
enqueued_record const& elem = m_queue.top();
if (static_cast< uint64_t >((now - elem.m_timestamp).milliseconds()) >= m_ordering_window)
{
// We got a new element
rec = elem.m_record;
m_queue.pop();
return true;
}
}
return false;
}