3 * Copyright 2005 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
24 typedef boost::shared_ptr<gr_msg_queue> gr_msg_queue_sptr;
25 %template(gr_msg_queue_sptr) boost::shared_ptr<gr_msg_queue>;
27 %rename(msg_queue) gr_make_msg_queue;
28 gr_msg_queue_sptr gr_make_msg_queue(unsigned limit=0);
31 * \brief thread-safe message queue
34 class gr_msg_queue : public gr_msg_handler {
36 omni_condition d_cond;
37 gr_message_sptr d_head;
38 gr_message_sptr d_tail;
45 //! Generic msg_handler method: insert the message.
46 //void handle(gr_message_sptr msg) { insert_tail (msg); }
49 * \brief Insert message at tail of queue.
52 * Block if queue if full.
54 //void insert_tail(gr_message_sptr msg);
57 * \brief Delete message from head of queue and return it.
58 * Block if no message is available.
60 //gr_message_sptr delete_head();
63 * \brief If there's a message in the q, delete it and return it.
64 * If no message is available, return 0.
66 gr_message_sptr delete_head_nowait();
68 //! is the queue empty?
71 //! is the queue full?
74 //! return number of messages in queue
75 unsigned int count() const;
77 //! Delete all messages from the queue
82 * The following kludge-o-rama releases the Python global interpreter
83 * lock around these potentially blocking calls. We don't want
84 * libgnuradio-core to be dependent on Python, thus we create these
85 * functions that serve as replacements for the normal C++ delete_head
86 * and insert_tail methods. The %pythoncode smashes these new C++
87 * functions into the gr.msg_queue wrapper class, so that everything
88 * appears normal. (An evil laugh is heard in the distance...)
91 gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) {
93 Py_BEGIN_ALLOW_THREADS; // release global interpreter lock
94 msg = q->delete_head(); // possibly blocking call
95 Py_END_ALLOW_THREADS; // acquire global interpreter lock
99 void gr_py_msg_queue__insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) {
100 Py_BEGIN_ALLOW_THREADS; // release global interpreter lock
101 q->insert_tail(msg); // possibly blocking call
102 Py_END_ALLOW_THREADS; // acquire global interpreter lock
106 // smash in new python delete_head and insert_tail methods...
108 gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head
109 gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail
110 gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail