void l7vs::session_thread_control::upstream_run(){
state_tag state;
+ upthread_running_mutex.lock();
{ // get first state from class upstream state.
- boost::mutex::scoped_lock upcond_lock( upthread_condition_mutex ); // upstream state lock
+ rw_scoped_lock upstate_lock( upthread_state_mutex );
state = upthread_state; //thread local state is update.
}
-// boost::mutex::scoped_lock up_exit_lock( upthread_exit_mutex );
for(;;){ // thread loop
if( state == WAIT ){ // after create or session end. this thread is pooling mode
boost::mutex::scoped_lock lock( upthread_condition_mutex );
- upthread_condition.wait( lock ); // thread is condition wait.( start at notify_all() )
+// upthread_condition.wait( lock ); // thread is condition wait.( start at notify_all() )
+ boost::xtime wait;
+ boost::xtime_get( &wait, boost::TIME_UTC );
+ wait.sec += 1;
+ upthread_running_mutex.unlock();
+ upthread_condition.timed_wait( lock, wait ); // thread is condition wait( start at notify_all() )
+ upthread_running_mutex.lock();
}
else if( state == EXIT ){ // this state is vitrualservice end. thread is finishing.
break;
session->up_thread_run(); //session upstream thread looping.
stopupstream();
}
- boost::mutex::scoped_lock upcond_lock( upthread_condition_mutex ); // upstream state lock
+ rw_scoped_lock upstate_lock( upthread_state_mutex );
state = upthread_state; //thread local state is update.
}
+ upthread_running_mutex.unlock();
+ boost::mutex::scoped_lock up_lk( upthread_joining_mutex );
+ upthread_joining_condition.notify_all();
}
void l7vs::session_thread_control::downstream_run(){
state_tag state;
+ downthread_running_mutex.lock();
{
- boost::mutex::scoped_lock downcond_lock( downthread_condition_mutex ); //downstream state is lock
+ rw_scoped_lock downstate_lock( downthread_state_mutex );
state = downthread_state; //thread local state is update.
}
-// boost::mutex::scoped_lock down_exit_lock( downthread_exit_mutex );
for(;;){ //thread loop
if( state == WAIT ){ //after create or session end. this thread is pooling mode
boost::mutex::scoped_lock lock( downthread_condition_mutex );
- downthread_condition.wait( lock ); // thread is condition wait( start at notify_all() )
+// downthread_condition.wait( lock ); // thread is condition wait( start at notify_all() )
+ boost::xtime wait;
+ boost::xtime_get( &wait, boost::TIME_UTC );
+ wait.sec += 1;
+ downthread_running_mutex.unlock();
+ downthread_condition.timed_wait( lock, wait ); // thread is condition wait( start at notify_all() )
+ downthread_running_mutex.lock();
}
else if( state == EXIT ){// this state is vitrualservice end. thread is finishing.
break;
session->down_thread_run();//session downstream thread looping.
stopdownstream();
}
- boost::mutex::scoped_lock downcond_lock( downthread_condition_mutex ); //downstream state lock
+ rw_scoped_lock downstate_lock( downthread_state_mutex );
state = downthread_state; // thread local sate is update.
}
+ downthread_running_mutex.unlock();
+ boost::mutex::scoped_lock down_lk( downthread_joining_mutex );
+ downthread_joining_condition.notify_all();
}
void l7vs::session_thread_control::startupstream(){
// unit_test[5] release_session method test(stopすると、sessionスレッドからrelease_sessionが呼ばれる)
BOOST_MESSAGE( "-------5" );
BOOST_CHECK( vs->get_pool_sessions().size() == (l7vs::virtualservice_base::SESSION_POOL_NUM_DEFAULT-1) );
- BOOST_CHECK( vs->get_active_sessions().size() == 1 );
- vs->release_session( vs->get_active_sessions().begin()->second->get_upthread_id() );
+ BOOST_CHECK( vs->get_waiting_sessions().size() == 1 );
+ BOOST_CHECK( vs->get_active_sessions().size() == 0 );
+ vs->release_session( vs->get_waiting_sessions().begin()->second->get_upthread_id() );
BOOST_CHECK( vs->get_pool_sessions().size() == static_cast<size_t>( l7vs::virtualservice_base::SESSION_POOL_NUM_DEFAULT) );
BOOST_CHECK( vs->get_active_sessions().size() == 0 );
+ BOOST_CHECK( vs->get_waiting_sessions().size() == 0 );
// unit_test[6] stop method test(call twice)
BOOST_MESSAGE( "-------6" );
test_suite* ts = BOOST_TEST_SUITE( "virtualservice_base_test" );
// add test case to test suite
-/* ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test1 ) );
+ ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test1 ) );
ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test2 ) );
ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test3 ) );
- ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test4 ) );*/
+ ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test4 ) );
ts->add( BOOST_TEST_CASE( &virtualservice_tcp_test5 ) );
framework::master_test_suite().add( ts );
}
unsigned long long get_refcount(){
- return rs_list_ref_count.get();
+// return rs_list_ref_count.get();
+ return rs_list_ref_count;
}
void set_refcount( unsigned long long in ){
rs_list_ref_count = in;
}
unsigned long long get_curr_up_recv_size(){
- return current_up_recvsize.get();
+// return current_up_recvsize.get();
+ return current_up_recvsize;
}
unsigned long long get_curr_down_recv_size(){
- return current_down_recvsize.get();
+// return current_down_recvsize.get();
+ return current_down_recvsize;
}
void call_handle_throughput_update( const boost::system::error_code& err ){
boost::xtime_get( &diffelencial_time, boost::TIME_UTC );