本文整理汇总了C++中queue_type::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ queue_type::empty方法的具体用法?C++ queue_type::empty怎么用?C++ queue_type::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue_type
的用法示例。
在下文中一共展示了queue_type::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_pair
inline std::pair<T, bool> try_dequeue_in_critical_section() {
T elem = T();
// Wait while the queue is empty and this queue is alive
if (m_queue.empty() || m_alive == false) {
return std::make_pair(elem, false);
}
else {
elem = m_queue.front();
m_queue.pop_front();
if (m_queue.empty() && sleeping_on_empty) {
m_empty_conditional.signal();
}
return std::make_pair(elem, true);
}
}
示例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: enqueue_unlocked
//! Enqueues a log record
void enqueue_unlocked(record_view const& rec)
{
const bool was_empty = m_queue.empty();
m_queue.push(enqueued_record(rec));
if (was_empty)
m_cond.notify_one();
}
示例4: swap
void swap(queue_type &q) {
m_mutex.lock();
q.swap(m_queue);
if (m_queue.empty() && sleeping_on_empty) {
m_empty_conditional.signal();
}
m_mutex.unlock();
}
示例5: pop
boost::optional<T> pop(unsigned int timeout = 5) {
boost::unique_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(timeout));
if (!lock || queue_.empty())
return boost::optional<T>();
boost::optional<T> ret = queue_.front();
queue_.pop();
return ret;
}
示例6: make_pair
/**
* Returns an element if the queue has an entry.
* returns [item, false] otherwise.
*/
inline std::pair<T, bool> try_dequeue() {
if (m_queue.empty() || m_alive == false) return std::make_pair(T(), false);
m_mutex.lock();
T elem = T();
// Wait while the queue is empty and this queue is alive
if (m_queue.empty() || m_alive == false) {
m_mutex.unlock();
return std::make_pair(elem, false);
}
else {
elem = m_queue.front();
m_queue.pop_front();
}
m_mutex.unlock();
return std::make_pair(elem, true);
}
示例7: wait_for_data
inline bool wait_for_data() {
m_mutex.lock();
bool success = false;
// Wait while the queue is empty and this queue is alive
while(m_queue.empty() && m_alive) {
sleeping++;
fiber_sleep();
sleeping--;
}
// An element has been added or a signal was raised
if(!m_queue.empty()) {
success = true;
}
m_mutex.unlock();
return success;
}
示例8: 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;
}
示例9: 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.
}
示例10: 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;
}
示例11: wait_until_empty
/**
* The conceptual "reverse" of dequeue().
* This function will block until the queue becomes empty, or
* until stop_blocking() is called.
* Returns true on success.
* Returns false if the queue is no longer alive
*/
bool wait_until_empty() {
m_mutex.lock();
// if the queue still has elements in it while I am still alive, wait
while (m_queue.empty() == false && m_alive == true) {
sleeping_on_empty++;
m_empty_conditional.wait(m_mutex);
sleeping_on_empty--;
}
m_mutex.unlock();
// if I am alive, the queue must be empty. i.e. success
// otherwise I am dead
return m_alive;
}
示例12: 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();
}
示例13:
//! Prefix increment of the iterator.
iterator& operator++()
{
if (!m_valid) return *this;
if (m_queue.empty()) {
m_valid = false;
return *this;
}
value_type v = m_queue.front();
m_queue.pop();
value_type child = m_cst->select_child(v, 1);
while (m_cst->root() != child) {
m_queue.push(child);
child = m_cst->sibling(child);
}
return *this;
}
示例14: process_queue
void process_queue(const Handler& h, const boost::system::error_code& ec,
std::chrono::milliseconds repeat, int repeat_count) {
// Process up to m_batch_size items waiting on the queue.
// For each dequeued item call m_wait_handler
int i = 0; // Number of handler invocations
T value;
while (i < m_batch_size && m_queue.pop(value)) {
i++;
repeat_count = dec_repeat_count(repeat_count);
if (!h(value, boost::system::error_code()))
return;
}
static const auto s_timeout =
boost::system::errc::make_error_code(boost::system::errc::timed_out);
auto pthis = this->shared_from_this();
// If we reached the batch size and queue has more data
// to process - give up the time slice and reschedule the handler
if (i == m_batch_size && !m_queue.empty()) {
m_io.post([pthis, h, repeat, repeat_count]() {
(*pthis)(h, boost::asio::error::operation_aborted, repeat, repeat_count);
});
return;
} else if (!i && !h(value, s_timeout)) {
// If we haven't processed any data and the timer was canceled.
// Invoke the callback to see if we need to remove the handler.
return;
}
int n = dec_repeat_count(repeat_count);
// If requested repeated timer, schedule new timer invocation
if (repeat > std::chrono::milliseconds(0) && n > 0) {
m_timer.cancel();
m_timer.expires_from_now(repeat);
m_timer.async_wait(
[pthis, h, repeat, n]
(const boost::system::error_code& ec) {
(*pthis)(h, ec, repeat, n);
});
}
}
示例15: 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;
}