3 * Copyright 2005,2009 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 gr_msg_queue(unsigned int limit);
39 //! Generic msg_handler method: insert the message.
40 //void handle(gr_message_sptr msg) { insert_tail (msg); }
43 * \brief Insert message at tail of queue.
46 * Block if queue if full.
48 //void insert_tail(gr_message_sptr msg);
51 * \brief Delete message from head of queue and return it.
52 * Block if no message is available.
54 //gr_message_sptr delete_head();
57 * \brief If there's a message in the q, delete it and return it.
58 * If no message is available, return 0.
60 gr_message_sptr delete_head_nowait();
62 //! is the queue empty?
65 //! is the queue full?
68 //! return number of messages in queue
69 unsigned int count() const;
71 //! Delete all messages from the queue
76 * The following kludge-o-rama releases the Python global interpreter
77 * lock around these potentially blocking calls. We don't want
78 * libgnuradio-core to be dependent on Python, thus we create these
79 * functions that serve as replacements for the normal C++ delete_head
80 * and insert_tail methods. The %pythoncode smashes these new C++
81 * functions into the gr.msg_queue wrapper class, so that everything
82 * appears normal. (An evil laugh is heard in the distance...)
85 gr_message_sptr gr_py_msg_queue__delete_head(gr_msg_queue_sptr q) {
87 Py_BEGIN_ALLOW_THREADS; // release global interpreter lock
88 msg = q->delete_head(); // possibly blocking call
89 Py_END_ALLOW_THREADS; // acquire global interpreter lock
93 void gr_py_msg_queue__insert_tail(gr_msg_queue_sptr q, gr_message_sptr msg) {
94 Py_BEGIN_ALLOW_THREADS; // release global interpreter lock
95 q->insert_tail(msg); // possibly blocking call
96 Py_END_ALLOW_THREADS; // acquire global interpreter lock
100 // smash in new python delete_head and insert_tail methods...
102 gr_msg_queue_sptr.delete_head = gr_py_msg_queue__delete_head
103 gr_msg_queue_sptr.insert_tail = gr_py_msg_queue__insert_tail
104 gr_msg_queue_sptr.handle = gr_py_msg_queue__insert_tail