diff options
author | Nate Goergen <nate.goergen.gitlab1@mile10.com> | 2015-03-19 12:12:10 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2015-04-02 15:38:58 -0700 |
commit | 1a773a2411fa18455d2e995060fa2e9f42afc007 (patch) | |
tree | 836bd3c93b5036f3e495c6132f874a05906b9cff | |
parent | 91459f9b06500ac16f555819ef3c20f2029483c8 (diff) |
controlport: cleaner, more robust interface for buffer gets.
-rw-r--r-- | gnuradio-runtime/include/gnuradio/rpcbufferedget.h | 58 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/rpcmanager.h | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/controlport/rpcmanager.cc | 14 | ||||
-rw-r--r-- | gnuradio-runtime/lib/controlport/rpcserver_selector.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_b_impl.cc | 31 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_b_impl.h | 6 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_c_impl.cc | 31 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_c_impl.h | 7 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_f_impl.cc | 32 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_f_impl.h | 7 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_i_impl.cc | 32 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_i_impl.h | 7 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_s_impl.cc | 31 | ||||
-rw-r--r-- | gr-blocks/lib/ctrlport_probe2_s_impl.h | 7 |
14 files changed, 106 insertions, 161 deletions
diff --git a/gnuradio-runtime/include/gnuradio/rpcbufferedget.h b/gnuradio-runtime/include/gnuradio/rpcbufferedget.h new file mode 100644 index 0000000000..5d2b529aa5 --- /dev/null +++ b/gnuradio-runtime/include/gnuradio/rpcbufferedget.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2015 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef RPCBUFFEREDGET_H +#define RPCBUFFEREDGET_H + +#include <boost/thread/condition_variable.hpp> +#include <boost/thread/mutex.hpp> + +template<typename TdataType> +class rpcbufferedget { +public: + rpcbufferedget(const unsigned int init_buffer_size = 4096) : + data_needed(false), data_ready(), buffer_lock(), buffer(init_buffer_size) {;} + + ~rpcbufferedget() {;} + + void offer_data(const TdataType& data) { + if (!data_needed) return; + buffer = data; + data_ready.notify_one(); + data_needed = false; + } + + TdataType get() { + boost::mutex::scoped_lock lock(buffer_lock); + data_needed = true; + data_ready.wait(lock); + return buffer; + } + +private: + bool data_needed; + boost::condition_variable data_ready; + boost::mutex buffer_lock; + TdataType buffer; +}; + +#endif diff --git a/gnuradio-runtime/include/gnuradio/rpcmanager.h b/gnuradio-runtime/include/gnuradio/rpcmanager.h index 5635572a8b..e7ee4c4942 100644 --- a/gnuradio-runtime/include/gnuradio/rpcmanager.h +++ b/gnuradio-runtime/include/gnuradio/rpcmanager.h @@ -54,7 +54,7 @@ class GR_RUNTIME_API rpcmanager : public virtual rpcmanager_base static bool booter_registered; static bool aggregator_registered; static void rpcserver_booter_base_sptr_dest(rpcserver_booter_base* b) {;} - static rpcserver_booter_base* boot; + static std::auto_ptr<rpcserver_booter_base> boot; static std::auto_ptr<rpcserver_booter_aggregator> aggregator; }; diff --git a/gnuradio-runtime/lib/controlport/rpcmanager.cc b/gnuradio-runtime/lib/controlport/rpcmanager.cc index 0c7bc135be..a67febe386 100644 --- a/gnuradio-runtime/lib/controlport/rpcmanager.cc +++ b/gnuradio-runtime/lib/controlport/rpcmanager.cc @@ -26,16 +26,12 @@ bool rpcmanager::booter_registered(false); bool rpcmanager::aggregator_registered(false); -rpcserver_booter_base* rpcmanager::boot(0); +std::auto_ptr<rpcserver_booter_base> rpcmanager::boot(0); std::auto_ptr<rpcserver_booter_aggregator> rpcmanager::aggregator(0); rpcmanager::rpcmanager() {;} -rpcmanager::~rpcmanager() -{ - if(boot) - delete boot; -} +rpcmanager::~rpcmanager() {;} rpcserver_booter_base* rpcmanager::get() @@ -44,10 +40,10 @@ rpcmanager::get() return aggregator.get(); } else if(booter_registered) { - return boot; + return boot.get(); } assert(booter_registered || aggregator_registered); - return boot; + return boot.get(); } void @@ -63,7 +59,7 @@ rpcmanager::register_booter(rpcserver_booter_base* booter) aggregator->agg()->registerServer(bootreg); } else if(!booter_registered) { - boot = booter; + boot.reset(booter); booter_registered = true; } else { diff --git a/gnuradio-runtime/lib/controlport/rpcserver_selector.cc b/gnuradio-runtime/lib/controlport/rpcserver_selector.cc index bfb6eb9d7e..8f3b4557c2 100644 --- a/gnuradio-runtime/lib/controlport/rpcserver_selector.cc +++ b/gnuradio-runtime/lib/controlport/rpcserver_selector.cc @@ -27,7 +27,7 @@ bool rpcmanager::make_aggregator(false); #ifdef GR_RPCSERVER_ENABLED -rpcmanager manager_instance;; +rpcmanager manager_instance; #endif #ifdef GR_RPCSERVER_ICE diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.cc b/gr-blocks/lib/ctrlport_probe2_b_impl.cc index e6e2570ea6..3cf2ae0167 100644 --- a/gr-blocks/lib/ctrlport_probe2_b_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_b_impl.cc @@ -63,26 +63,9 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<signed char> - ctrlport_probe2_b_impl::get() - { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<signed char> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + ctrlport_probe2_b_impl::get() { + return buffered_get.get(); } void @@ -112,7 +95,6 @@ namespace gr { const char *in = (const char*)input_items[0]; // copy samples to get buffer if we need samples - mutex_buffer.lock(); if(d_buffer.size() < d_len) { // copy smaller of remaining buffer space and num inputs to work() int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); @@ -121,13 +103,12 @@ namespace gr { for(int i = 0; i < num_copy; i++) { d_buffer.push_back(in[i]); } + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + // notify the waiting get() if we fill up the buffer + if(d_buffer.size() == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } diff --git a/gr-blocks/lib/ctrlport_probe2_b_impl.h b/gr-blocks/lib/ctrlport_probe2_b_impl.h index 155dd4c23c..490af9b040 100644 --- a/gr-blocks/lib/ctrlport_probe2_b_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_b_impl.h @@ -25,7 +25,7 @@ #include <gnuradio/blocks/ctrlport_probe2_b.h> #include <gnuradio/rpcregisterhelpers.h> -#include <boost/thread/shared_mutex.hpp> +#include <gnuradio/rpcbufferedget.h> namespace gr { namespace blocks { @@ -37,11 +37,9 @@ namespace gr { std::string d_desc; size_t d_len; unsigned int d_disp_mask; - boost::shared_mutex mutex_buffer; - mutable boost::mutex mutex_notify; - boost::condition_variable condition_buffer_ready; std::vector<signed char> d_buffer; + rpcbufferedget< std::vector<signed char> > buffered_get; public: ctrlport_probe2_b_impl(const std::string &id, const std::string &desc, diff --git a/gr-blocks/lib/ctrlport_probe2_c_impl.cc b/gr-blocks/lib/ctrlport_probe2_c_impl.cc index aa038c0765..bd43130be5 100644 --- a/gr-blocks/lib/ctrlport_probe2_c_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_c_impl.cc @@ -64,26 +64,9 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<gr_complex> - ctrlport_probe2_c_impl::get() - { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<gr_complex> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + ctrlport_probe2_c_impl::get() { + return buffered_get.get(); } void @@ -113,7 +96,6 @@ namespace gr { const gr_complex *in = (const gr_complex*)input_items[0]; // copy samples to get buffer if we need samples - mutex_buffer.lock(); if(d_buffer.size() < d_len) { // copy smaller of remaining buffer space and num inputs to work() int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); @@ -122,13 +104,12 @@ namespace gr { for(int i = 0; i < num_copy; i++) { d_buffer.push_back(in[i]); } + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + // notify the waiting get() if we fill up the buffer + if(d_buffer.size() == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } diff --git a/gr-blocks/lib/ctrlport_probe2_c_impl.h b/gr-blocks/lib/ctrlport_probe2_c_impl.h index 15ff0f4ea2..fa74216202 100644 --- a/gr-blocks/lib/ctrlport_probe2_c_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_c_impl.h @@ -25,7 +25,7 @@ #include <gnuradio/blocks/ctrlport_probe2_c.h> #include <gnuradio/rpcregisterhelpers.h> -#include <boost/thread/shared_mutex.hpp> +#include <gnuradio/rpcbufferedget.h> namespace gr { namespace blocks { @@ -37,11 +37,9 @@ namespace gr { std::string d_desc; size_t d_len; unsigned int d_disp_mask; - boost::shared_mutex mutex_buffer; - mutable boost::mutex mutex_notify; - boost::condition_variable condition_buffer_ready; std::vector<gr_complex> d_buffer; + rpcbufferedget< std::vector<gr_complex> > buffered_get; public: ctrlport_probe2_c_impl(const std::string &id, const std::string &desc, @@ -66,4 +64,3 @@ namespace gr { } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_C_IMPL_H */ - diff --git a/gr-blocks/lib/ctrlport_probe2_f_impl.cc b/gr-blocks/lib/ctrlport_probe2_f_impl.cc index b53b2dc3cb..05d67da9dd 100644 --- a/gr-blocks/lib/ctrlport_probe2_f_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_f_impl.cc @@ -62,26 +62,9 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<float> - ctrlport_probe2_f_impl::get() - { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<float> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + ctrlport_probe2_f_impl::get() { + return buffered_get.get(); } void @@ -111,7 +94,6 @@ namespace gr { const float *in = (const float*)input_items[0]; // copy samples to get buffer if we need samples - mutex_buffer.lock(); if(d_buffer.size() < d_len) { // copy smaller of remaining buffer space and num inputs to work() int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); @@ -120,13 +102,13 @@ namespace gr { for(int i = 0; i < num_copy; i++) { d_buffer.push_back(in[i]); } + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + + // notify the waiting get() if we fill up the buffer + if(d_buffer.size() == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } diff --git a/gr-blocks/lib/ctrlport_probe2_f_impl.h b/gr-blocks/lib/ctrlport_probe2_f_impl.h index a4aa099237..8d406db927 100644 --- a/gr-blocks/lib/ctrlport_probe2_f_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_f_impl.h @@ -25,7 +25,7 @@ #include <gnuradio/blocks/ctrlport_probe2_f.h> #include <gnuradio/rpcregisterhelpers.h> -#include <boost/thread/shared_mutex.hpp> +#include <gnuradio/rpcbufferedget.h> namespace gr { namespace blocks { @@ -37,11 +37,9 @@ namespace gr { std::string d_desc; size_t d_len; unsigned int d_disp_mask; - boost::shared_mutex mutex_buffer; - mutable boost::mutex mutex_notify; - boost::condition_variable condition_buffer_ready; std::vector<float> d_buffer; + rpcbufferedget< std::vector<float> > buffered_get; public: ctrlport_probe2_f_impl(const std::string &id, const std::string &desc, @@ -66,4 +64,3 @@ namespace gr { } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_F_IMPL_H */ - diff --git a/gr-blocks/lib/ctrlport_probe2_i_impl.cc b/gr-blocks/lib/ctrlport_probe2_i_impl.cc index 77dca2ad0d..086ebe7cf0 100644 --- a/gr-blocks/lib/ctrlport_probe2_i_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_i_impl.cc @@ -64,26 +64,9 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<int> - ctrlport_probe2_i_impl::get() - { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<int> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + ctrlport_probe2_i_impl::get() { + return buffered_get.get(); } void @@ -111,9 +94,7 @@ namespace gr { gr_vector_void_star &output_items) { const int *in = (const int*)input_items[0]; - // copy samples to get buffer if we need samples - mutex_buffer.lock(); if(d_buffer.size() < d_len) { // copy smaller of remaining buffer space and num inputs to work() int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); @@ -122,13 +103,12 @@ namespace gr { for(int i = 0; i < num_copy; i++) { d_buffer.push_back(in[i]); } + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + // notify the waiting get() if we fill up the buffer + if(d_buffer.size() == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } diff --git a/gr-blocks/lib/ctrlport_probe2_i_impl.h b/gr-blocks/lib/ctrlport_probe2_i_impl.h index 06493ac23a..3a976550eb 100644 --- a/gr-blocks/lib/ctrlport_probe2_i_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_i_impl.h @@ -25,7 +25,7 @@ #include <gnuradio/blocks/ctrlport_probe2_i.h> #include <gnuradio/rpcregisterhelpers.h> -#include <boost/thread/shared_mutex.hpp> +#include <gnuradio/rpcbufferedget.h> namespace gr { namespace blocks { @@ -37,11 +37,9 @@ namespace gr { std::string d_desc; size_t d_len; unsigned int d_disp_mask; - boost::shared_mutex mutex_buffer; - mutable boost::mutex mutex_notify; - boost::condition_variable condition_buffer_ready; std::vector<int> d_buffer; + rpcbufferedget< std::vector<int> > buffered_get; public: ctrlport_probe2_i_impl(const std::string &id, const std::string &desc, @@ -66,4 +64,3 @@ namespace gr { } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_I_IMPL_H */ - diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.cc b/gr-blocks/lib/ctrlport_probe2_s_impl.cc index 6a4ade462c..d6a15faaef 100644 --- a/gr-blocks/lib/ctrlport_probe2_s_impl.cc +++ b/gr-blocks/lib/ctrlport_probe2_s_impl.cc @@ -64,26 +64,9 @@ namespace gr { ninput_items_required[i] = d_len; } - // boost::shared_mutex mutex_buffer; - // mutable boost::mutex mutex_notify; - // boost::condition_variable condition_buffer_ready; std::vector<short> - ctrlport_probe2_s_impl::get() - { - mutex_buffer.lock(); - d_buffer.clear(); - mutex_buffer.unlock(); - - // wait for condition - boost::mutex::scoped_lock lock(mutex_notify); - condition_buffer_ready.wait(lock); - - mutex_buffer.lock(); - std::vector<short> buf_copy = d_buffer; - assert(buf_copy.size() == d_len); - mutex_buffer.unlock(); - - return buf_copy; + ctrlport_probe2_s_impl::get() { + return buffered_get.get(); } void @@ -113,7 +96,6 @@ namespace gr { const short *in = (const short*)input_items[0]; // copy samples to get buffer if we need samples - mutex_buffer.lock(); if(d_buffer.size() < d_len) { // copy smaller of remaining buffer space and num inputs to work() int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items ); @@ -122,13 +104,12 @@ namespace gr { for(int i = 0; i < num_copy; i++) { d_buffer.push_back(in[i]); } + } - // notify the waiting get() if we fill up the buffer - if(d_buffer.size() == d_len) { - condition_buffer_ready.notify_one(); - } + // notify the waiting get() if we fill up the buffer + if(d_buffer.size() == d_len) { + buffered_get.offer_data(d_buffer); } - mutex_buffer.unlock(); return noutput_items; } diff --git a/gr-blocks/lib/ctrlport_probe2_s_impl.h b/gr-blocks/lib/ctrlport_probe2_s_impl.h index 078dd56b73..49533ced6f 100644 --- a/gr-blocks/lib/ctrlport_probe2_s_impl.h +++ b/gr-blocks/lib/ctrlport_probe2_s_impl.h @@ -25,7 +25,7 @@ #include <gnuradio/blocks/ctrlport_probe2_s.h> #include <gnuradio/rpcregisterhelpers.h> -#include <boost/thread/shared_mutex.hpp> +#include <gnuradio/rpcbufferedget.h> namespace gr { namespace blocks { @@ -37,11 +37,9 @@ namespace gr { std::string d_desc; size_t d_len; unsigned int d_disp_mask; - boost::shared_mutex mutex_buffer; - mutable boost::mutex mutex_notify; - boost::condition_variable condition_buffer_ready; std::vector<short> d_buffer; + rpcbufferedget< std::vector<short> > buffered_get; public: ctrlport_probe2_s_impl(const std::string &id, const std::string &desc, @@ -66,4 +64,3 @@ namespace gr { } /* namespace gr */ #endif /* INCLUDED_CTRLPORT_PROBE2_S_IMPL_H */ - |