[complement-svn] SF.net SVN: complement: [1502] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-02-01 17:23:08
|
Revision: 1502 http://svn.sourceforge.net/complement/?rev=1502&view=rev Author: complement Date: 2007-02-01 09:23:03 -0800 (Thu, 01 Feb 2007) Log Message: ----------- add 'signal' to thr_mgr---send signal to all good threads in pool; use fact, that thread's join in Thread destructor now. join in Thread destructor; timespec multiplication on double added Modified Paths: -------------- trunk/complement/explore/include/mt/thr_mgr.h trunk/complement/explore/include/mt/time.h trunk/complement/explore/lib/mt/ChangeLog trunk/complement/explore/lib/mt/thr_mgr.cc trunk/complement/explore/lib/mt/time.cc trunk/complement/explore/lib/mt/xmt.cc Modified: trunk/complement/explore/include/mt/thr_mgr.h =================================================================== --- trunk/complement/explore/include/mt/thr_mgr.h 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/include/mt/thr_mgr.h 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/13 17:41:15 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:39:25 ptr> /* * Copyright (c) 1997-1999, 2002, 2005, 2006 @@ -40,6 +40,7 @@ void launch( Thread::entrance_type entrance, const void *p = 0, size_t psz = 0, unsigned flags = 0, size_t stack_sz = 0 ); __FIT_DECLSPEC void garbage_collector(); __FIT_DECLSPEC void join(); + __FIT_DECLSPEC void signal( int ); container_type::size_type size(); Modified: trunk/complement/explore/include/mt/time.h =================================================================== --- trunk/complement/explore/include/mt/time.h 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/include/mt/time.h 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:21:37 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:35:14 ptr> /* * Copyright (c) 2002, 2006 @@ -57,6 +57,7 @@ ::timespec operator /( const ::timespec& a, unsigned long b ); ::timespec operator *( const ::timespec& a, unsigned b ); ::timespec operator *( const ::timespec& a, unsigned long b ); +::timespec operator *( const ::timespec& a, double b ); inline ::timespec operator *( unsigned b, const ::timespec& a ) { return a * b; } inline ::timespec operator *( unsigned long b, const ::timespec& a ) @@ -69,6 +70,7 @@ ::timespec& operator /=( ::timespec& a, unsigned long b ); ::timespec& operator *=( ::timespec& a, unsigned b ); ::timespec& operator *=( ::timespec& a, unsigned long b ); +::timespec& operator *=( ::timespec& a, double b ); bool operator >( const ::timespec& a, const ::timespec& b ); bool operator >=( const ::timespec& a, const ::timespec& b ); Modified: trunk/complement/explore/lib/mt/ChangeLog =================================================================== --- trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/ChangeLog 2007-02-01 17:23:03 UTC (rev 1502) @@ -3,8 +3,14 @@ * thr_mgr.cc: reduce amount of code; try to 'join' to already closed threads, wait other in loop. [this is attempt to find workaround for deadlock within glibc, but speedup release - already free resources too] + already free resources too]; add 'signal'---send signal to all + good threads in pool; use fact, that thread's join in Thread + destructor now. + * xmt.cc: join in Thread destructor. + + * time.h, time.cc: timespec multiplication on double added. + * libxmt: version 1.9.5 2007-01-30 Petr Ovtchenkov <pt...@is...> Modified: trunk/complement/explore/lib/mt/thr_mgr.cc =================================================================== --- trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/thr_mgr.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/02/01 11:18:04 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 20:17:50 ptr> /* * Copyright (c) 1997-1999, 2002, 2005-2007 @@ -15,8 +15,12 @@ #include <algorithm> #include <functional> +// #include <iostream> + namespace xmt { +// int _supercount = 0; + using namespace std; struct bad_thread : @@ -26,6 +30,13 @@ { return !__x->good(); } }; +struct good_thread : + public unary_function<Thread *,bool> +{ + bool operator()(const Thread *__x) const + { return (__x != 0) && (__x->good()); } +}; + struct rm_if_bad_thread : public unary_function<Thread *,bool> { @@ -37,14 +48,27 @@ if ( __x == 0 ) { return true; } - if ( !__x->good() ) { - __x->join(); + if ( __x->bad() ) { + // --_supercount; delete __x; return true; } return false; } +struct thread_signal : + public binary_function<Thread *,int,void> +{ + void operator()(const Thread *__x, int sig ) const; +}; + +void thread_signal::operator()(const Thread *__x, int sig ) const +{ + if ( __x != 0 ) { + const_cast<Thread *>(__x)->kill( sig ); + } +} + __FIT_DECLSPEC ThreadMgr::~ThreadMgr() { ThreadMgr::join(); @@ -58,12 +82,17 @@ // xmt::block_signal( SIGCHLD ); // xmt::block_signal( SIGPOLL ); - Locker lk( _lock ); + _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); while ( !_M_c.empty() ) { - xmt::delay( xmt::timespec(0,100000000) ); + _lock.unlock(); + xmt::delay( xmt::timespec(0,50000000) ); + _lock.lock(); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); + // cerr << "### " << _supercount << " " << _M_c.size() << endl; } + // _supercount = 0; + _lock.unlock(); } __FIT_DECLSPEC @@ -72,6 +101,7 @@ Locker lk( _lock ); _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); _M_c.push_back( new Thread( entrance, p, psz, flags, stack_sz ) ); + // ++_supercount; } __FIT_DECLSPEC @@ -84,8 +114,17 @@ ThreadMgr::container_type::size_type ThreadMgr::size() { Locker lk( _lock ); - _M_c.erase( remove_if( _M_c.begin(), _M_c.end(), rm_if_bad_thread() ), _M_c.end() ); - return _M_c.size(); + // ThreadMgr::container_type::size_type sz = count_if( _M_c.begin(), _M_c.end(), good_thread() ); + // cerr << "Sz: " << sz << endl; + + return count_if( _M_c.begin(), _M_c.end(), good_thread() ); } +__FIT_DECLSPEC void ThreadMgr::signal( int sig ) +{ + // cerr << "Signal!" << endl; + Locker lk( _lock ); + for_each( _M_c.begin(), _M_c.end(), bind2nd( thread_signal(), sig ) ); +} + } // namespace xmt Modified: trunk/complement/explore/lib/mt/time.cc =================================================================== --- trunk/complement/explore/lib/mt/time.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/time.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:35:48 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 18:34:48 ptr> /* * Copyright (c) 2002, 2003, 2006 @@ -141,6 +141,16 @@ return c; } +timespec operator *( const timespec& a, double b ) +{ + timespec c; + double d = (a.tv_sec + 1.0e-9 * a.tv_nsec) * b; + + c.tv_nsec = static_cast<long>(1.0e9 * modf( d, &d ) + 0.5); + c.tv_sec = static_cast<time_t>(d); + return c; +} + timespec& operator +=( timespec& a, const timespec& b ) { a.tv_sec += b.tv_sec; @@ -210,6 +220,16 @@ return a; } +timespec& operator *=( timespec& a, double b ) +{ + double d = (a.tv_sec + 1.0e-9 * a.tv_nsec) * b; + + a.tv_nsec = static_cast<long>(1.0e9 * modf( d, &d ) + 0.5); + a.tv_sec = static_cast<time_t>(d); + + return a; +} + bool operator ==( const timespec& a, const timespec& b ) { return (a.tv_sec == b.tv_sec) && (a.tv_nsec == b.tv_nsec); Modified: trunk/complement/explore/lib/mt/xmt.cc =================================================================== --- trunk/complement/explore/lib/mt/xmt.cc 2007-02-01 10:03:27 UTC (rev 1501) +++ trunk/complement/explore/lib/mt/xmt.cc 2007-02-01 17:23:03 UTC (rev 1502) @@ -1,7 +1,7 @@ -// -*- C++ -*- Time-stamp: <07/01/29 18:53:22 ptr> +// -*- C++ -*- Time-stamp: <07/02/01 19:35:59 ptr> /* - * Copyright (c) 1997-1999, 2002-2006 + * Copyright (c) 1997-1999, 2002-2007 * Petr Ovtchenkov * * Portion Copyright (c) 1999-2001 @@ -363,6 +363,8 @@ __FIT_DECLSPEC Thread::Thread( Thread::entrance_type entrance, const void *p, size_t psz, unsigned __f, size_t stack_sz ) : + _id( bad_thread_id ), + _state( badbit ), _entrance( entrance ), _param( 0 ), _param_sz( 0 ), @@ -377,6 +379,7 @@ __FIT_DECLSPEC Thread::~Thread() { + Thread::join(); ((Init *)Init_buf)->~Init(); // _STLP_ASSERT( _id == bad_thread_id ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |