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.
26 #include <gr_msg_queue.h>
30 gr_make_msg_queue(unsigned int limit)
32 return gr_msg_queue_sptr (new gr_msg_queue(limit));
35 gr_msg_queue::gr_msg_queue(unsigned int limit)
36 : d_not_empty(), d_not_full(),
37 /*d_head(0), d_tail(0),*/ d_count(0), d_limit(limit)
41 gr_msg_queue::~gr_msg_queue()
47 gr_msg_queue::insert_tail(gr_message_sptr msg)
50 throw std::invalid_argument("gr_msg_queue::insert_tail: msg already in queue");
52 gruel::scoped_lock guard(d_mutex);
55 d_not_full.wait(guard);
58 d_tail = d_head = msg;
69 d_not_empty.notify_one();
73 gr_msg_queue::delete_head()
75 gruel::scoped_lock guard(d_mutex);
78 while ((m = d_head) == 0)
79 d_not_empty.wait(guard);
90 d_not_full.notify_one();
95 gr_msg_queue::delete_head_nowait()
97 gruel::scoped_lock guard(d_mutex);
100 if ((m = d_head) == 0){
102 return gr_message_sptr();
114 d_not_full.notify_one();
119 gr_msg_queue::flush()
123 while ((m = delete_head_nowait ()) != 0)