コード例 #1
0
    //! 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;
    }
コード例 #2
0
ファイル: queue.hpp プロジェクト: mickem/nscp
		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;
		}
コード例 #3
0
	bool try_take_( callable & ca)
	{
		if ( empty_() )
			return false;
		callable tmp( queue_.top().ca);
		queue_.pop();
		ca.swap( tmp);
		return ! ca.empty();
	}
コード例 #4
0
 /// Try receive a packet from the incoming queue
 bool recv( packet_type &inpkt )
 {
     bool r=false;
     if( incoming_not_empty())
     {
         inpkt = m_incoming_queue.outgoing();
         m_incoming_queue.pop();
         r=true;
     }
     return r;
 }
コード例 #5
0
ファイル: LogServer.cpp プロジェクト: mjgerdes/cg
	void listen() {
		queue_element_type* msg(nullptr);
		while (true) {
			if (m_messageQueue.pop(msg)) {
				msg->write();
				delete msg;
			} else {
				using namespace std::literals;
				std::this_thread::sleep_for(3s);
			}
		}  // while
	}
コード例 #6
0
    //! 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;
    }
コード例 #7
0
    //! 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;
    }
コード例 #8
0
ファイル: test_queue.cpp プロジェクト: hundeboll/rlncd
    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;
    }
コード例 #9
0
ファイル: cst_iterators.hpp プロジェクト: olydis/sdsl-lite
	//! 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;
	}
コード例 #10
0
ファイル: test_queue.cpp プロジェクト: hundeboll/rlncd
    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();
    }
コード例 #11
0
ファイル: async_queue.hpp プロジェクト: erlanger/eixx
    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);
                });
        }
    }
コード例 #12
0
    //! 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;
    }
コード例 #13
0
ファイル: async_queue.hpp プロジェクト: erlanger/eixx
    bool async_dequeue(const Handler& a_on_data,
        std::chrono::milliseconds a_wait_duration = std::chrono::milliseconds(-1),
        int repeat_count = 0)
    {
        T value;
        if (m_queue.pop(value)) {
            if (!a_on_data(value, boost::system::error_code()))
                return true;
            if (repeat_count > 0) --repeat_count;
        }

        if (!repeat_count)
            return true;

        auto rep = repeat_count < 0 ? std::numeric_limits<int>::max() : repeat_count;

        std::chrono::milliseconds timeout =
            a_wait_duration < std::chrono::milliseconds(0)
                ? std::chrono::milliseconds::max()
                : a_wait_duration;

        if (timeout == std::chrono::milliseconds(0))
            m_io.post([this, &a_on_data, timeout, rep]() {
                (*this->shared_from_this())(
                    a_on_data, boost::system::error_code(), timeout, rep);
            });
        else {
            boost::system::error_code ec;
            m_timer.cancel(ec);
            m_timer.expires_from_now(timeout);
            auto pthis = this->shared_from_this();
            m_timer.async_wait(
                [pthis, &a_on_data, timeout, rep]
                (const boost::system::error_code& e) {
                    (*pthis)(a_on_data, e, timeout, rep);
                }
            );
        }

        return false;
    }
コード例 #14
0
    //! 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;
    }
コード例 #15
0
ファイル: simple_reactor.hpp プロジェクト: fmrl/blanchett
	virtual bool service()
	{
	   message_type msg;
	   (void)my_queue.pop(msg);
	   return msg->service();
	}
コード例 #16
0
ファイル: queue.hpp プロジェクト: maoy/mosaic
 void dequeue_( msg_type & msg)
 {
   msg = queue_.front();
   queue_.pop();
 }
コード例 #17
0
ファイル: async_queue.hpp プロジェクト: erlanger/eixx
 bool dequeue(T& value) {
     return m_queue.pop(value);
 }
コード例 #18
0
ファイル: async_queue.hpp プロジェクト: erlanger/eixx
    void reset() {
        cancel();

        T value;
        while (m_queue.pop(value));
    }
コード例 #19
0
ファイル: log.hpp プロジェクト: ssteinberg/ste
	void dump() {
		queue_type::stored_ptr entry;
		while ((entry = queue.pop()) != nullptr)
			write_entry(std::move(entry));
	}