commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 47/50: controlport: cleaner, more robust in


From: git
Subject: [Commit-gnuradio] [gnuradio] 47/50: controlport: cleaner, more robust interface for buffer gets.
Date: Wed, 15 Apr 2015 21:07:58 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 1a773a2411fa18455d2e995060fa2e9f42afc007
Author: Nate Goergen <address@hidden>
Date:   Thu Mar 19 12:12:10 2015 -0400

    controlport: cleaner, more robust interface for buffer gets.
---
 gnuradio-runtime/include/gnuradio/rpcbufferedget.h | 58 ++++++++++++++++++++++
 gnuradio-runtime/include/gnuradio/rpcmanager.h     |  2 +-
 gnuradio-runtime/lib/controlport/rpcmanager.cc     | 14 ++----
 .../lib/controlport/rpcserver_selector.cc          |  2 +-
 gr-blocks/lib/ctrlport_probe2_b_impl.cc            | 31 +++---------
 gr-blocks/lib/ctrlport_probe2_b_impl.h             |  6 +--
 gr-blocks/lib/ctrlport_probe2_c_impl.cc            | 31 +++---------
 gr-blocks/lib/ctrlport_probe2_c_impl.h             |  7 +--
 gr-blocks/lib/ctrlport_probe2_f_impl.cc            | 32 +++---------
 gr-blocks/lib/ctrlport_probe2_f_impl.h             |  7 +--
 gr-blocks/lib/ctrlport_probe2_i_impl.cc            | 32 +++---------
 gr-blocks/lib/ctrlport_probe2_i_impl.h             |  7 +--
 gr-blocks/lib/ctrlport_probe2_s_impl.cc            | 31 +++---------
 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 0000000..5d2b529
--- /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 5635572..e7ee4c4 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 0c7bc13..a67febe 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 bfb6eb9..8f3b455 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 e6e2570..3cf2ae0 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 155dd4c..490af9b 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 aa038c0..bd43130 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 15ff0f4..fa74216 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 b53b2dc..05d67da 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 a4aa099..8d406db 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 77dca2a..086ebe7 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 06493ac..3a97655 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 6a4ade4..d6a15fa 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 078dd56..49533ce 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 */
-



reply via email to

[Prev in Thread] Current Thread [Next in Thread]