using namespace std;
using boost::posix_time::microsec_clock;
using boost::posix_time::ptime;
+using boost::mutex;
using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
CurrentLinkStatus( LinkStatus_Down ),
CurrentNotificationStatus( NotificationStatus_NotReported ),
TimeLinkStatusChanged( microsec_clock::universal_time() ),
- StatusNotifierCmd( status_notifier_cmd )
+ StatusNotifierCmd( status_notifier_cmd ),
+ Mutex()
{
BOOST_ASSERT( 0 <= hosts_down_limit );
BOOST_ASSERT( 0 <= link_up_interval_in_min );
{
BOOST_ASSERT( !host_address.empty() );
+ Mutex.lock();
+
GlobalLogger.info() << "- Host up: " << host_address << endl;
add_host_up( host_address );
// removed from the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 0 );
+
+ Mutex.unlock();
}
void LinkStatusAnalyzer::notify_host_down( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
+ Mutex.lock();
+
GlobalLogger.info() << "- Host down: " << host_address << endl;
add_host_down( host_address );
// inserted in the list?
BOOST_ASSERT( HostsDownList.count( host_address ) == 1 );
+
+ Mutex.unlock();
}
void LinkStatusAnalyzer::add_host_up( const string &host_address )
#include <string>
#include <boost/asio.hpp>
+#include <boost/thread/mutex.hpp>
#include "link/statusnotifiercommand.h"
boost::posix_time::ptime TimeLinkStatusChanged;
/// command used to notify the status of the link
StatusNotifierCommand StatusNotifierCmd;
-
+ /// mutual exclusion variable to avoid data races
+ boost::mutex Mutex;
};