GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
messages/msg_queue.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2009,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef INCLUDED_MSG_QUEUE_H
24#define INCLUDED_MSG_QUEUE_H
25
26#include <gnuradio/api.h>
28#include <pmt/pmt.h>
29#include <deque>
30
31namespace gr {
32namespace messages {
33
34class msg_queue;
35typedef boost::shared_ptr<msg_queue> msg_queue_sptr;
36
37msg_queue_sptr make_msg_queue(unsigned int limit = 0);
38
39/*!
40 * \brief thread-safe message queue
41 */
43{
44private:
45 gr::thread::mutex d_mutex;
48 unsigned int d_limit; // max # of messages in queue. 0 -> unbounded
49
50 std::deque<pmt::pmt_t> d_msgs;
51
52public:
53 msg_queue(unsigned int limit);
55
56 /*!
57 * \brief Insert message at tail of queue.
58 * \param msg message
59 *
60 * Block if queue if full.
61 */
63
64 /*!
65 * \brief Delete message from head of queue and return it.
66 * Block if no message is available.
67 */
69
70 /*!
71 * \brief If there's a message in the q, delete it and return it.
72 * If no message is available, return pmt::pmt_t().
73 */
75
76 //! Delete all messages from the queue
77 void flush();
78
79 //! is the queue empty?
80 bool empty_p() const { return d_msgs.empty(); }
81
82 //! is the queue full?
83 bool full_p() const { return d_limit != 0 && count() >= d_limit; }
84
85 //! return number of messages in queue
86 unsigned int count() const { return d_msgs.size(); }
87
88 //! return limit on number of message in queue. 0 -> unbounded
89 unsigned int limit() const { return d_limit; }
90};
91
92} /* namespace messages */
93} /* namespace gr */
94
95#endif /* INCLUDED_MSG_QUEUE_H */
thread-safe message queue
Definition: messages/msg_queue.h:43
bool full_p() const
is the queue full?
Definition: messages/msg_queue.h:83
pmt::pmt_t delete_head_nowait()
If there's a message in the q, delete it and return it. If no message is available,...
void flush()
Delete all messages from the queue.
bool empty_p() const
is the queue empty?
Definition: messages/msg_queue.h:80
unsigned int count() const
return number of messages in queue
Definition: messages/msg_queue.h:86
pmt::pmt_t delete_head()
Delete message from head of queue and return it. Block if no message is available.
void insert_tail(pmt::pmt_t msg)
Insert message at tail of queue.
unsigned int limit() const
return limit on number of message in queue. 0 -> unbounded
Definition: messages/msg_queue.h:89
msg_queue(unsigned int limit)
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
static purpose_t msg
Definition: source_logger.h:39
msg_queue_sptr make_msg_queue(unsigned int limit=0)
boost::mutex mutex
Definition: thread.h:48
boost::condition_variable condition_variable
Definition: thread.h:50
Include this header to use the message passing features.
Definition: basic_block.h:45
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost....
Definition: pmt.h:56