profile_lock.h

00001 
00006 #pragma once
00007 
00008 #include <boost/thread.hpp>
00009 #include <usml/ocean/profile_model.h>
00010 
00011 namespace usml {
00012 namespace ocean {
00013 
00014 using boost::numeric::ublas::vector;
00015 
00018 
00023 class USML_DECLSPEC profile_lock : public profile_model {
00024 
00025    private:
00026 
00028                 boost::mutex* _sound_speedMutex ;
00029                 boost::mutex* _attenuationMutex ;
00031         profile_model* _other;
00032 
00033     public:
00034 
00040         profile_lock(profile_model* other) : _other(other)
00041         {
00042             _sound_speedMutex = new boost::mutex();
00043             _attenuationMutex = new boost::mutex();
00044         }
00045 
00054         virtual void sound_speed( const wposition& location,
00055             matrix<double>* speed, wvector* gradient=NULL )
00056         {
00057             // Locks mutex then unlocks on method exit
00058             // Avoids try/catch on _other->sound_speed call
00059             boost::lock_guard<boost::mutex> sound_speedLock(*_sound_speedMutex);
00060 
00061             _other->sound_speed(location, speed, gradient);
00062 
00063         }
00064 
00073         virtual void attenuation(
00074            const usml::types::wposition& location,
00075            const seq_vector& frequencies,
00076            const boost::numeric::ublas::matrix<double>& distance,
00077            boost::numeric::ublas::matrix< boost::numeric::ublas::vector<double> >* attenuation)
00078        {
00079             // Locks mutex then unlocks on method exit
00080             // Avoids try/catch on _other->attenuation call
00081             boost::lock_guard<boost::mutex> attenuationLock(*_attenuationMutex);
00082 
00083             _other->attenuation(location, frequencies, distance, attenuation ) ;
00084        }
00085 
00089         virtual ~profile_lock()
00090         {
00091             if (_sound_speedMutex || _attenuationMutex)
00092             {
00093                delete _sound_speedMutex;
00094                delete _attenuationMutex;
00095                _sound_speedMutex = _attenuationMutex = NULL;
00096             }
00097             delete _other ;
00098         }
00099 };
00100 
00102 }  // end of namespace ocean
00103 }  // end of namespace usml

Generated on 4 May 2015 for USML by  doxygen 1.6.1