#define REALSERVER_H
#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
#include "realserver_element.h"
namespace l7vs{
class realserver : public realserver_element{
+public:
+ typedef boost::shared_ptr<boost::mutex> mutex_ptr;
protected:
- int nactive;
- int ninact;
- boost::mutex active_mutex;
- boost::mutex inact_mutex;
+ int nactive;
+ int ninact;
+ mutex_ptr active_mutex_ptr;
+ mutex_ptr inact_mutex_ptr;
public:
unsigned long long send_byte;
- realserver() : nactive(0), ninact(0), send_byte(0LL){}
+ realserver() : nactive(0), ninact(0), send_byte(0LL){
+ active_mutex_ptr = mutex_ptr( new boost::mutex );
+ inact_mutex_ptr = mutex_ptr( new boost::mutex );
+ }
realserver( const realserver& in ) : realserver_element( in ),
nactive( in.nactive ),
ninact( in.ninact ),
- send_byte( in.send_byte ){}
+ send_byte( in.send_byte ){
+ active_mutex_ptr = mutex_ptr( new boost::mutex );
+ inact_mutex_ptr = mutex_ptr( new boost::mutex );
+ }
realserver& operator=( const realserver& rs ){
realserver_element::operator= (rs);
}
void increment_active(){
+ boost::mutex::scoped_lock( active_mutex_ptr );
+
nactive++;
if ( nactive == INT_MAX ){
nactive = 0;
}
}
+
void decrement_active(){
+ boost::mutex::scoped_lock( active_mutex_ptr );
+
if ( nactive > 0 ){
nactive--;
}
}
+
void increment_inact(){
+ boost::mutex::scoped_lock( inact_mutex_ptr );
+
ninact++;
if ( ninact == INT_MAX ){
ninact = 0;
}
}
+
int get_active(){
return nactive;
}
+
int get_inact(){
return ninact;
}
//! destractor
~realserver_fake(){}
- void set_active( const int in_active ){ nactive = in_active ; }
- void set_inact( const int in_inact ){ ninact = in_inact ; }
+ void set_active( const int in_active ){
+ boost::mutex::scoped_lock( active_mutex_ptr );
+
+ nactive = in_active ;
+ }
+ void set_inact( const int in_inact ){
+ boost::mutex::scoped_lock( inact_mutex_ptr );
+
+ ninact = in_inact ;
+ }
void increment_active2( const std::string& msg1, const std::string& msg2 ){
boost::mutex::scoped_lock lock( starting_mutex );
BOOST_CHECK_EQUAL( server1.get_active(), 0 );
// unit_test[26] 接続数インクリメントメソッドのテスト2(上限INT_MAXに達すると0にクリア)
+ BOOST_MESSAGE( "wait a minute to INT_MAX" );
for ( loop = 0; loop < INT_MAX; loop++ ){
server1.increment_active();
}
BOOST_CHECK_EQUAL( server1.get_inact(), 1 );
// unit_test[29] 切断数インクリメントメソッドのテスト2(上限INT_MAXに達すると0にクリア)
+ BOOST_MESSAGE( "wait a minute to INT_MAX" );
for ( loop = server1.get_inact(); loop < INT_MAX; loop++ ){
server1.increment_inact();
}