GNU Radio Manual and C++ API Reference  3.7.13.4
The Free & Open Software Radio Ecosystem
rpcbufferedget.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 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 RPCBUFFEREDGET_H
24 #define RPCBUFFEREDGET_H
25 
26 #include <boost/thread/condition_variable.hpp>
27 #include <boost/thread/mutex.hpp>
28 
29 template<typename TdataType>
31 public:
32  rpcbufferedget(const unsigned int init_buffer_size = 4096) :
33  d_data_needed(false), d_data_ready(), d_buffer_lock(), d_buffer(init_buffer_size) {;}
34 
36  d_data_ready.notify_all();
37  }
38 
39  void offer_data(const TdataType& data) {
40  if (!d_data_needed)
41  return;
42  {
43  boost::mutex::scoped_lock lock(d_buffer_lock);
44  d_buffer = data;
45  d_data_needed = false;
46  }
47  d_data_ready.notify_one();
48  }
49 
50  TdataType get() {
51  boost::mutex::scoped_lock lock(d_buffer_lock);
52  d_data_needed = true;
53  d_data_ready.wait(lock);
54  return d_buffer;
55  }
56 
57 private:
58  bool d_data_needed;
59  boost::condition_variable d_data_ready;
60  boost::mutex d_buffer_lock;
61  TdataType d_buffer;
62 };
63 
64 #endif
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:49
Definition: rpcbufferedget.h:30
void offer_data(const TdataType &data)
Definition: rpcbufferedget.h:39
~rpcbufferedget()
Definition: rpcbufferedget.h:35
rpcbufferedget(const unsigned int init_buffer_size=4096)
Definition: rpcbufferedget.h:32
boost::mutex mutex
Definition: thread.h:48
boost::condition_variable condition_variable
Definition: thread.h:50