GNU Radio Manual and C++ API Reference 3.7.14.0
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
29template <typename TdataType>
31{
32public:
33 rpcbufferedget(const unsigned int init_buffer_size = 4096)
34 : d_data_needed(false),
35 d_data_ready(),
36 d_buffer_lock(),
37 d_buffer(init_buffer_size)
38 {
39 ;
40 }
41
42 ~rpcbufferedget() { d_data_ready.notify_all(); }
43
44 void offer_data(const TdataType& data)
45 {
46 if (!d_data_needed)
47 return;
48 {
49 boost::mutex::scoped_lock lock(d_buffer_lock);
50 d_buffer = data;
51 d_data_needed = false;
52 }
53 d_data_ready.notify_one();
54 }
55
56 TdataType get()
57 {
58 boost::mutex::scoped_lock lock(d_buffer_lock);
59 d_data_needed = true;
60 d_data_ready.wait(lock);
61 return d_buffer;
62 }
63
64private:
65 bool d_data_needed;
66 boost::condition_variable d_data_ready;
67 boost::mutex d_buffer_lock;
68 TdataType d_buffer;
69};
70
71#endif
Definition: rpcbufferedget.h:31
~rpcbufferedget()
Definition: rpcbufferedget.h:42
void offer_data(const TdataType &data)
Definition: rpcbufferedget.h:44
TdataType get()
Definition: rpcbufferedget.h:56
rpcbufferedget(const unsigned int init_buffer_size=4096)
Definition: rpcbufferedget.h:33
boost::mutex mutex
Definition: thread.h:48
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:49
boost::condition_variable condition_variable
Definition: thread.h:50