[complement-svn] SF.net SVN: complement: [1503] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-02-01 17:24:53
|
Revision: 1503 http://svn.sourceforge.net/complement/?rev=1503&view=rev Author: complement Date: 2007-02-01 09:24:46 -0800 (Thu, 01 Feb 2007) Log Message: ----------- start connect_processor threads only from 'observer' thread; threads pool managed only from 'observer' thread; 'observer' thread not in threads pool, it start from 'loop'; libsockios: Version 1.10.4 Modified Paths: -------------- trunk/complement/explore/include/sockios/sockmgr.cc trunk/complement/explore/include/sockios/sockmgr.h trunk/complement/explore/lib/sockios/ChangeLog trunk/complement/explore/lib/sockios/Makefile.inc Modified: trunk/complement/explore/include/sockios/sockmgr.cc =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/include/sockios/sockmgr.cc 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 10:04:23 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 19:50:14 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -321,48 +321,31 @@ _Self_type *me = static_cast<_Self_type *>(p); me->loop_id.pword( _idx ) = me; // push pointer to self for signal processing xmt::Thread::ret_code rtc; + xmt::Thread::ret_code rtc_observer; rtc.iword = 0; + rtc_observer.iword = 0; + xmt::Thread thr_observer; + try { me->_loop_cnd.set( true ); me->_follow = true; - me->_observer_run = false; while ( (me->*me->_accept)() ) { - if ( me->mgr.size() < 2 ) { - me->mgr.launch( connect_processor, me ); + if ( thr_observer.bad() ) { + if ( thr_observer.is_join_req() ) { + rtc_observer = thr_observer.join(); + if ( rtc_observer.iword != 0 ) { + rtc.iword = -2; // there was connect_processor that was killed + } + } + thr_observer.launch( observer, me, 0, PTHREAD_STACK_MIN * 2 ); } - me->_orlock.lock(); - if ( !me->_observer_run ) { - me->_observer_run = true; - me->_orlock.unlock(); - me->mgr.launch( observer, me, 0, 0, PTHREAD_STACK_MIN * 2 ); - } else { - me->_orlock.unlock(); - } } } catch ( ... ) { - me->_dlock.lock(); - me->_follow = false; - me->_pool_cnd.set( true, true ); - me->_observer_cnd.set( true ); - me->_dlock.unlock(); - - // me->_c_lock.lock(); - ::close( me->_cfd ); - ::close( me->_pfd[1].fd ); - me->close(); - // me->_c_lock.unlock(); rtc.iword = -1; - - me->mgr.join(); - - me->_M_c.clear(); // FIN still may not come yet; forse close - - return rtc; - // throw; } xmt::block_signal( SIGINT ); @@ -381,11 +364,13 @@ ::close( me->_pfd[1].fd ); me->close(); // me->_c_lock.unlock(); + rtc_observer = thr_observer.join(); - me->mgr.join(); + me->_M_c.clear(); // FIN still may not come yet; force close + if ( rtc_observer.iword != 0 && rtc.iword == 0 ) { + rtc.iword = -2; // there was connect_processor that was killed + } - me->_M_c.clear(); // FIN still may not come yet; forse close - return rtc; } @@ -464,6 +449,7 @@ } while ( me->_is_follow() && idle_count < 2 ); } catch ( ... ) { + rtc.iword = -1; } return rtc; @@ -487,6 +473,10 @@ std::fill( pool_size, pool_size + 3, 0 ); try { + xmt::ThreadMgr mgr; + + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); + do { // std::swap( pool_size[0], pool_size[1] ); std::rotate( pool_size, pool_size, pool_size + 3 ); @@ -496,37 +486,45 @@ tpop = me->_tpop; } if ( pool_size[2] != 0 ) { - if ( me->_thr_limit > me->mgr.size() ) { + if ( me->_thr_limit > mgr.size() ) { if ( (pool_size[0] - 2 * pool_size[1] + pool_size[2]) > 0 || - pool_size[2] > 32 + pool_size[2] > me->_thr_limit /* pool_size[1] > 3 && pool_size[0] <= pool_size[1] */ ) { // queue not empty and not decrease - me->mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } else { xmt::gettime( &now ); if ( (tpop + delta) < now ) { // a long time was since last pop from queue - me->mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); + mgr.launch( connect_processor, me /* , 0, 0, PTHREAD_STACK_MIN * 2 */ ); } } } + mgr.garbage_collector(); xmt::delay( &alarm ); } else { - if ( me->_observer_cnd.try_wait_delay( &idle ) != 0 ) { - MT_REENTRANT( me->_orlock, _1 ); - me->_observer_run = false; - + if ( /* me->_is_follow() && */ me->_observer_cnd.try_wait_delay( &idle ) != 0 && mgr.size() == 0 ) { return rtc; } } } while ( me->_is_follow() ); + + int count = 24; + while ( mgr.size() > 0 && count > 0 ) { + me->_pool_cnd.set( true, true ); + xmt::delay( &alarm ); + alarm *= 1.2; + --count; + } + if ( mgr.size() > 0 ) { + mgr.signal( SIGTERM ); + rtc.iword = -1; + } } catch ( ... ) { + rtc.iword = -1; } - MT_REENTRANT( me->_orlock, _1 ); - me->_observer_run = false; - return rtc; } Modified: trunk/complement/explore/include/sockios/sockmgr.h =================================================================== --- trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/include/sockios/sockmgr.h 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/01/31 23:52:05 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 16:10:07 ptr> /* * Copyright (c) 1997-1999, 2002, 2003, 2005-2007 @@ -297,15 +297,11 @@ xmt::Condition _pool_cnd; xmt::Mutex _dlock; timespec _tpop; - xmt::ThreadMgr mgr; xmt::Mutex _flock; bool _follow; xmt::Condition _observer_cnd; - xmt::Mutex _orlock; - bool _observer_run; - timespec _busylimit; // start new thread to process incoming // requests, if processing thread busy // more then _busylimit Modified: trunk/complement/explore/lib/sockios/ChangeLog =================================================================== --- trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/lib/sockios/ChangeLog 2007-02-01 17:24:46 UTC (rev 1503) @@ -6,6 +6,13 @@ * libsockios: Version 1.10.3 + * sockmgr.h, sockmgr.cc: start connect_processor threads + only from 'observer' thread; threads pool managed only + from 'observer' thread; 'observer' thread not in threads + pool, it start from 'loop'; + + * libsockios: Version 1.10.4 + 2007-01-31 Petr Ovtchenkov <pt...@is...> * sockmgr.h, sockmgr.cc: really erase iterators Modified: trunk/complement/explore/lib/sockios/Makefile.inc =================================================================== --- trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-01 17:23:03 UTC (rev 1502) +++ trunk/complement/explore/lib/sockios/Makefile.inc 2007-02-01 17:24:46 UTC (rev 1503) @@ -1,9 +1,9 @@ -# -*- Makefile -*- Time-stamp: <07/01/31 10:07:17 ptr> +# -*- Makefile -*- Time-stamp: <07/02/01 19:53:51 ptr> LIBNAME = sockios MAJOR = 1 MINOR = 10 -PATCH = 2 +PATCH = 4 SRC_CC = _sockstream.cc _sockmgr.cc SRC_C = freebsd/getaddrinfo.c \ freebsd/ns_parse.c \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |