[hamradio-commits] [gnss-sdr] 15/80: Improve memory management

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Sun May 15 20:11:52 UTC 2016


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

carles_fernandez-guest pushed a commit to branch upstream
in repository gnss-sdr.

commit fbfc4a28ba4e3814321ce9730c0c8702c488fcd4
Author: Carles Fernandez <carles.fernandez at gmail.com>
Date:   Mon May 2 17:26:32 2016 +0200

    Improve memory management
    
    The blocks are now always managed by smart pointers instead of raw pointers
---
 src/algorithms/channel/adapters/channel.cc         |  6 +--
 src/algorithms/channel/adapters/channel.h          | 18 ++++----
 src/algorithms/channel/libs/channel_fsm.cc         |  6 +--
 src/algorithms/channel/libs/channel_fsm.h          | 10 ++---
 .../adapters/array_signal_conditioner.cc           | 14 ++----
 .../adapters/array_signal_conditioner.h            | 16 +++----
 .../conditioner/adapters/signal_conditioner.cc     | 10 ++---
 .../conditioner/adapters/signal_conditioner.h      | 16 +++----
 src/core/receiver/gnss_block_factory.cc            | 52 +++++++++++-----------
 9 files changed, 69 insertions(+), 79 deletions(-)

diff --git a/src/algorithms/channel/adapters/channel.cc b/src/algorithms/channel/adapters/channel.cc
index 0495d89..df6597c 100644
--- a/src/algorithms/channel/adapters/channel.cc
+++ b/src/algorithms/channel/adapters/channel.cc
@@ -43,11 +43,10 @@ using google::LogMessage;
 
 // Constructor
 Channel::Channel(ConfigurationInterface *configuration, unsigned int channel,
-        GNSSBlockInterface *pass_through, AcquisitionInterface *acq,
-        TrackingInterface *trk, TelemetryDecoderInterface *nav,
+        std::shared_ptr<GNSSBlockInterface> pass_through, std::shared_ptr<AcquisitionInterface> acq,
+        std::shared_ptr<TrackingInterface> trk, std::shared_ptr<TelemetryDecoderInterface> nav,
         std::string role, std::string implementation, boost::shared_ptr<gr::msg_queue> queue)
 {
-
     pass_through_ = pass_through;
     acq_ = acq;
     trk_ = trk;
@@ -187,3 +186,4 @@ void Channel::start_acquisition()
 {
     channel_fsm_.Event_start_acquisition();
 }
+
diff --git a/src/algorithms/channel/adapters/channel.h b/src/algorithms/channel/adapters/channel.h
index 664b5ef..0d2a304 100644
--- a/src/algorithms/channel/adapters/channel.h
+++ b/src/algorithms/channel/adapters/channel.h
@@ -61,8 +61,8 @@ class Channel: public ChannelInterface
 public:
     //! Constructor
     Channel(ConfigurationInterface *configuration, unsigned int channel,
-            GNSSBlockInterface *pass_through, AcquisitionInterface *acq,
-            TrackingInterface *trk, TelemetryDecoderInterface *nav,
+            std::shared_ptr<GNSSBlockInterface> pass_through, std::shared_ptr<AcquisitionInterface> acq,
+            std::shared_ptr<TrackingInterface> trk, std::shared_ptr<TelemetryDecoderInterface> nav,
             std::string role, std::string implementation,
             boost::shared_ptr<gr::msg_queue> queue);
     //! Virtual destructor
@@ -77,9 +77,9 @@ public:
     std::string implementation(){ return implementation_; }
     size_t item_size(){ return 0; }
     Gnss_Signal get_signal() const { return gnss_signal_; }
-    AcquisitionInterface* acquisition(){ return acq_; }
-    TrackingInterface* tracking(){ return trk_; }
-    TelemetryDecoderInterface* telemetry(){ return nav_; }
+    std::shared_ptr<AcquisitionInterface> acquisition(){ return acq_; }
+    std::shared_ptr<TrackingInterface> tracking(){ return trk_; }
+    std::shared_ptr<TelemetryDecoderInterface> telemetry(){ return nav_; }
     void start_acquisition();                   //!< Start the State Machine
     void set_signal(const Gnss_Signal& gnss_signal_);  //!< Sets the channel GNSS signal
 
@@ -88,10 +88,10 @@ public:
 
 private:
     channel_msg_receiver_cc_sptr channel_msg_rx;
-    GNSSBlockInterface *pass_through_;
-    AcquisitionInterface *acq_;
-    TrackingInterface *trk_;
-    TelemetryDecoderInterface *nav_;
+    std::shared_ptr<GNSSBlockInterface> pass_through_;
+    std::shared_ptr<AcquisitionInterface> acq_;
+    std::shared_ptr<TrackingInterface> trk_;
+    std::shared_ptr<TelemetryDecoderInterface> nav_;
     std::string role_;
     std::string implementation_;
     unsigned int channel_;
diff --git a/src/algorithms/channel/libs/channel_fsm.cc b/src/algorithms/channel/libs/channel_fsm.cc
index be55bbf..b8698d0 100644
--- a/src/algorithms/channel/libs/channel_fsm.cc
+++ b/src/algorithms/channel/libs/channel_fsm.cc
@@ -136,7 +136,7 @@ ChannelFsm::ChannelFsm()
 
 
 
-ChannelFsm::ChannelFsm(AcquisitionInterface *acquisition) :
+ChannelFsm::ChannelFsm(std::shared_ptr<AcquisitionInterface> acquisition) :
 	        acq_(acquisition)
 {
     trk_ = nullptr;
@@ -180,12 +180,12 @@ void ChannelFsm::Event_failed_tracking_standby()
 //	this->process_event(Ev_channel_failed_tracking_reacq());
 //}
 
-void ChannelFsm::set_acquisition(AcquisitionInterface *acquisition)
+void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition)
 {
     acq_ = acquisition;
 }
 
-void ChannelFsm::set_tracking(TrackingInterface *tracking)
+void ChannelFsm::set_tracking(std::shared_ptr<TrackingInterface> tracking)
 {
     trk_ = tracking;
 }
diff --git a/src/algorithms/channel/libs/channel_fsm.h b/src/algorithms/channel/libs/channel_fsm.h
index 6fa2a6d..868388b 100644
--- a/src/algorithms/channel/libs/channel_fsm.h
+++ b/src/algorithms/channel/libs/channel_fsm.h
@@ -55,10 +55,10 @@ class ChannelFsm: public sc::state_machine<ChannelFsm, channel_idle_fsm_S0>
 {
 public:
     ChannelFsm();
-    ChannelFsm(AcquisitionInterface *acquisition);
+    ChannelFsm(std::shared_ptr<AcquisitionInterface> acquisition);
 
-    void set_acquisition(AcquisitionInterface *acquisition);
-    void set_tracking(TrackingInterface *tracking);
+    void set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition);
+    void set_tracking(std::shared_ptr<TrackingInterface> tracking);
     void set_queue(boost::shared_ptr<gr::msg_queue> queue);
     void set_channel(unsigned int channel);
     void start_acquisition();
@@ -75,8 +75,8 @@ public:
     void Event_failed_tracking_standby();
 
 private:
-    AcquisitionInterface *acq_;
-    TrackingInterface *trk_;
+    std::shared_ptr<AcquisitionInterface> acq_;
+    std::shared_ptr<TrackingInterface> trk_;
     boost::shared_ptr<gr::msg_queue> queue_;
     unsigned int channel_;
 };
diff --git a/src/algorithms/conditioner/adapters/array_signal_conditioner.cc b/src/algorithms/conditioner/adapters/array_signal_conditioner.cc
index 5a826da..d40adeb 100644
--- a/src/algorithms/conditioner/adapters/array_signal_conditioner.cc
+++ b/src/algorithms/conditioner/adapters/array_signal_conditioner.cc
@@ -37,8 +37,8 @@ using google::LogMessage;
 
 // Constructor
 ArraySignalConditioner::ArraySignalConditioner(ConfigurationInterface *configuration,
-        GNSSBlockInterface *data_type_adapt, GNSSBlockInterface *in_filt,
-        GNSSBlockInterface *res, std::string role, std::string implementation,
+        std::shared_ptr<GNSSBlockInterface> data_type_adapt, std::shared_ptr<GNSSBlockInterface> in_filt,
+        std::shared_ptr<GNSSBlockInterface> res, std::string role, std::string implementation,
         boost::shared_ptr<gr::msg_queue> queue) : data_type_adapt_(data_type_adapt),
                 in_filt_(in_filt), res_(res), role_(role), implementation_(implementation),
                 queue_(queue)
@@ -50,17 +50,12 @@ ArraySignalConditioner::ArraySignalConditioner(ConfigurationInterface *configura
 
 // Destructor
 ArraySignalConditioner::~ArraySignalConditioner()
-{
-    delete data_type_adapt_;
-    delete in_filt_;
-    delete res_;
-}
-
+{}
 
 
 void ArraySignalConditioner::connect(gr::top_block_sptr top_block)
 {
-	// note: the array signal conditioner do not have data type adapter, and must use the array input filter (multichannel)
+    // note: the array signal conditioner do not have data type adapter, and must use the array input filter (multichannel)
     if (connected_)
         {
             LOG(WARNING) << "Array Signal conditioner already connected internally";
@@ -70,7 +65,6 @@ void ArraySignalConditioner::connect(gr::top_block_sptr top_block)
     in_filt_->connect(top_block);
     res_->connect(top_block);
 
-
     //top_block->connect(data_type_adapt_->get_right_block(), 0, in_filt_->get_left_block(), 0);
     //DLOG(INFO) << "data_type_adapter -> input_filter";
 
diff --git a/src/algorithms/conditioner/adapters/array_signal_conditioner.h b/src/algorithms/conditioner/adapters/array_signal_conditioner.h
index 3dbb59b..1a635da 100644
--- a/src/algorithms/conditioner/adapters/array_signal_conditioner.h
+++ b/src/algorithms/conditioner/adapters/array_signal_conditioner.h
@@ -52,8 +52,8 @@ class ArraySignalConditioner: public GNSSBlockInterface
 public:
     //! Constructor
     ArraySignalConditioner(ConfigurationInterface *configuration,
-            GNSSBlockInterface *data_type_adapt, GNSSBlockInterface *in_filt,
-            GNSSBlockInterface *res, std::string role, std::string implementation,
+            std::shared_ptr<GNSSBlockInterface> data_type_adapt, std::shared_ptr<GNSSBlockInterface> in_filt,
+            std::shared_ptr<GNSSBlockInterface> res, std::string role, std::string implementation,
             boost::shared_ptr<gr::msg_queue> queue);
 
     //! Virtual destructor
@@ -69,14 +69,14 @@ public:
     std::string implementation(){ return "Array_Signal_Conditioner"; }
     size_t item_size(){ return 0; }
 
-    GNSSBlockInterface *data_type_adapter(){ return data_type_adapt_; }
-    GNSSBlockInterface *input_filter(){ return in_filt_; }
-    GNSSBlockInterface *resampler(){ return res_; }
+    std::shared_ptr<GNSSBlockInterface> data_type_adapter(){ return data_type_adapt_; }
+    std::shared_ptr<GNSSBlockInterface> input_filter(){ return in_filt_; }
+    std::shared_ptr<GNSSBlockInterface> resampler(){ return res_; }
 
 private:
-    GNSSBlockInterface *data_type_adapt_;
-    GNSSBlockInterface *in_filt_;
-    GNSSBlockInterface *res_;
+    std::shared_ptr<GNSSBlockInterface> data_type_adapt_;
+    std::shared_ptr<GNSSBlockInterface> in_filt_;
+    std::shared_ptr<GNSSBlockInterface> res_;
     std::string role_;
     std::string implementation_;
     bool connected_;
diff --git a/src/algorithms/conditioner/adapters/signal_conditioner.cc b/src/algorithms/conditioner/adapters/signal_conditioner.cc
index 3a57e38..42feb8f 100644
--- a/src/algorithms/conditioner/adapters/signal_conditioner.cc
+++ b/src/algorithms/conditioner/adapters/signal_conditioner.cc
@@ -37,8 +37,8 @@ using google::LogMessage;
 
 // Constructor
 SignalConditioner::SignalConditioner(ConfigurationInterface *configuration,
-        GNSSBlockInterface *data_type_adapt, GNSSBlockInterface *in_filt,
-        GNSSBlockInterface *res, std::string role, std::string implementation,
+        std::shared_ptr<GNSSBlockInterface> data_type_adapt, std::shared_ptr<GNSSBlockInterface> in_filt,
+        std::shared_ptr<GNSSBlockInterface> res, std::string role, std::string implementation,
         boost::shared_ptr<gr::msg_queue> queue) : data_type_adapt_(data_type_adapt),
                 in_filt_(in_filt), res_(res), role_(role), implementation_(implementation),
                 queue_(queue)
@@ -50,11 +50,7 @@ SignalConditioner::SignalConditioner(ConfigurationInterface *configuration,
 
 // Destructor
 SignalConditioner::~SignalConditioner()
-{
-    delete data_type_adapt_;
-    delete in_filt_;
-    delete res_;
-}
+{}
 
 
 void SignalConditioner::connect(gr::top_block_sptr top_block)
diff --git a/src/algorithms/conditioner/adapters/signal_conditioner.h b/src/algorithms/conditioner/adapters/signal_conditioner.h
index 41201a4..ef46a64 100644
--- a/src/algorithms/conditioner/adapters/signal_conditioner.h
+++ b/src/algorithms/conditioner/adapters/signal_conditioner.h
@@ -51,8 +51,8 @@ class SignalConditioner: public GNSSBlockInterface
 public:
     //! Constructor
     SignalConditioner(ConfigurationInterface *configuration,
-            GNSSBlockInterface *data_type_adapt, GNSSBlockInterface *in_filt,
-            GNSSBlockInterface *res, std::string role, std::string implementation,
+            std::shared_ptr<GNSSBlockInterface> data_type_adapt, std::shared_ptr<GNSSBlockInterface> in_filt,
+            std::shared_ptr<GNSSBlockInterface> res, std::string role, std::string implementation,
             boost::shared_ptr<gr::msg_queue> queue);
 
     //! Virtual destructor
@@ -68,14 +68,14 @@ public:
     std::string implementation(){ return "Signal_Conditioner"; }
     size_t item_size(){ return 0; }
 
-    GNSSBlockInterface *data_type_adapter(){ return data_type_adapt_; }
-    GNSSBlockInterface *input_filter(){ return in_filt_; }
-    GNSSBlockInterface *resampler(){ return res_; }
+    std::shared_ptr<GNSSBlockInterface> data_type_adapter(){ return data_type_adapt_; }
+    std::shared_ptr<GNSSBlockInterface> input_filter(){ return in_filt_; }
+    std::shared_ptr<GNSSBlockInterface> resampler(){ return res_; }
 
 private:
-    GNSSBlockInterface *data_type_adapt_;
-    GNSSBlockInterface *in_filt_;
-    GNSSBlockInterface *res_;
+    std::shared_ptr<GNSSBlockInterface> data_type_adapt_;
+    std::shared_ptr<GNSSBlockInterface> in_filt_;
+    std::shared_ptr<GNSSBlockInterface> res_;
     std::string role_;
     std::string implementation_;
     bool connected_;
diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc
index f7a17f3..d337d40 100644
--- a/src/core/receiver/gnss_block_factory.cc
+++ b/src/core/receiver/gnss_block_factory.cc
@@ -199,21 +199,21 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetSignalConditioner(
     if(signal_conditioner.compare("Array_Signal_Conditioner") == 0)
         {
             //instantiate the array version
-            std::unique_ptr<GNSSBlockInterface> conditioner_(new ArraySignalConditioner(configuration.get(), GetBlock(configuration,
-                    role_datatypeadapter, data_type_adapter, 1, 1, queue).release(), GetBlock(
-                            configuration,role_inputfilter, input_filter, 1, 1, queue).release(),
-                            GetBlock(configuration,role_resampler, resampler, 1, 1, queue).release(),
-                            role_conditioner, "Signal_Conditioner", queue));
+            std::unique_ptr<GNSSBlockInterface> conditioner_(new ArraySignalConditioner(configuration.get(), 
+                std::move(GetBlock(configuration, role_datatypeadapter, data_type_adapter, 1, 1, queue)), 
+                std::move(GetBlock(configuration, role_inputfilter, input_filter, 1, 1, queue)),
+                std::move(GetBlock(configuration, role_resampler, resampler, 1, 1, queue)),
+                role_conditioner, "Signal_Conditioner", queue));
             return conditioner_;
         }
     else
         {
             //single-antenna version
-            std::unique_ptr<GNSSBlockInterface> conditioner_(new SignalConditioner(configuration.get(), GetBlock(configuration,
-                    role_datatypeadapter, data_type_adapter, 1, 1, queue).release(), GetBlock(
-                            configuration,role_inputfilter, input_filter, 1, 1, queue).release(),
-                            GetBlock(configuration,role_resampler, resampler, 1, 1, queue).release(),
-                            role_conditioner, "Signal_Conditioner", queue));
+            std::unique_ptr<GNSSBlockInterface> conditioner_(new SignalConditioner(configuration.get(),
+                std::move(GetBlock(configuration, role_datatypeadapter, data_type_adapter, 1, 1, queue)), 
+                std::move(GetBlock(configuration, role_inputfilter, input_filter, 1, 1, queue)),
+                std::move(GetBlock(configuration, role_resampler, resampler, 1, 1, queue)),
+                role_conditioner, "Signal_Conditioner", queue));
             return conditioner_;
         }
 }
@@ -296,10 +296,10 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetChannel_1C(
     std::unique_ptr<TrackingInterface> trk_ = GetTrkBlock(configuration, "Tracking_1C"+ appendix2, trk, 1, 1, queue);
     std::unique_ptr<TelemetryDecoderInterface> tlm_ = GetTlmBlock(configuration, "TelemetryDecoder_1C" + appendix3, tlm, 1, 1);
 
-    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, pass_through_.release(),
-            acq_.release(),
-            trk_.release(),
-            tlm_.release(),
+    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, std::move(pass_through_),
+            std::move(acq_),
+            std::move(trk_),
+            std::move(tlm_),
             "Channel", "1C", queue));
 
     return channel_;
@@ -351,10 +351,10 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetChannel_2S(
 
     std::unique_ptr<TelemetryDecoderInterface> tlm_ = GetTlmBlock(configuration, "TelemetryDecoder_2S" + appendix3, tlm, 1, 1);
 
-    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, pass_through_.release(),
-            acq_.release(),
-            trk_.release(),
-            tlm_.release(),
+    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, std::move(pass_through_),
+            std::move(acq_),
+            std::move(trk_),
+            std::move(tlm_),
             "Channel", "2S", queue));
 
     return channel_;
@@ -407,10 +407,10 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetChannel_1B(
     std::unique_ptr<TrackingInterface> trk_ = GetTrkBlock(configuration, "Tracking_1B" + appendix2, trk, 1, 1, queue);
     std::unique_ptr<TelemetryDecoderInterface> tlm_ = GetTlmBlock(configuration, "TelemetryDecoder_1B" + appendix3, tlm, 1, 1);
 
-    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, pass_through_.release(),
-            acq_.release(),
-            trk_.release(),
-            tlm_.release(),
+    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, std::move(pass_through_),
+            std::move(acq_),
+            std::move(trk_),
+            std::move(tlm_),
             "Channel", "1B", queue));
 
     return channel_;
@@ -463,10 +463,10 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetChannel_5X(
     std::unique_ptr<TrackingInterface> trk_ = GetTrkBlock(configuration, "Tracking_5X" + appendix2, trk, 1, 1, queue);
     std::unique_ptr<TelemetryDecoderInterface> tlm_ = GetTlmBlock(configuration, "TelemetryDecoder_5X" + appendix3, tlm, 1, 1);
 
-    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, pass_through_.release(),
-            acq_.release(),
-            trk_.release(),
-            tlm_.release(),
+    std::unique_ptr<GNSSBlockInterface> channel_(new Channel(configuration.get(), channel, std::move(pass_through_),
+            std::move(acq_),
+            std::move(trk_),
+            std::move(tlm_),
             "Channel", "5X", queue));
 
     return channel_;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/gnss-sdr.git



More information about the pkg-hamradio-commits mailing list