Changeset 3240 for code/branches/netp6/src/core/ThreadPool.cc
- Timestamp:
- Jun 28, 2009, 3:04:30 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp6/src/core/ThreadPool.cc
r3231 r3240 28 28 29 29 #include "ThreadPool.h" 30 #include "Thread.h" 30 31 #include <cassert> 31 32 … … 39 40 ThreadPool::~ThreadPool() 40 41 { 42 unsigned int a = this->setNrOfThreads(0); 43 assert(a == 0); 41 44 } 42 45 … … 44 47 { 45 48 for( unsigned int i=0; i<nr; i++ ) 46 this->threadPool_.push_back( Thread());49 this->threadPool_.push_back(new Thread()); 47 50 } 48 51 unsigned int ThreadPool::removeThreads( unsigned int nr ) 49 52 { 50 53 unsigned int i=0; 51 std::vector<Thread >::iterator it;52 for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; ++it)54 std::vector<Thread*>::iterator it; 55 for( it = this->threadPool_.begin(); it != threadPool_.end() && i<nr; ) 53 56 { 54 if( ! it->isWorking() )57 if( ! (*it)->isWorking() ) 55 58 { 56 this->threadPool_.erase( it++ ); 59 Thread* temp = *it; 60 it=this->threadPool_.erase( it ); 61 delete temp; 57 62 ++i; 58 63 } 64 else 65 ++it; 59 66 } 60 67 return i; … … 74 81 } 75 82 76 bool ThreadPool::passFunction( Functor* functor, bool addThread )83 bool ThreadPool::passFunction( Executor* executor, bool addThread ) 77 84 { 78 std::vector<Thread >::iterator it;85 std::vector<Thread*>::iterator it; 79 86 for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it ) 80 87 { 81 if ( ! it->isWorking() )88 if ( ! (*it)->isWorking() ) 82 89 { 83 bool b = it->evaluateFunctor( functor );90 bool b = (*it)->evaluateExecutor( executor ); 84 91 assert(b); // if b is false then there is some code error 85 92 return true; … … 89 96 { 90 97 addThreads( 1 ); 91 this->threadPool_.back().evaluateFunctor( functor ); // access the last element 98 bool b = this->threadPool_.back()->evaluateExecutor( executor ); // access the last element 99 assert(b); 92 100 return true; 93 101 } … … 98 106 void ThreadPool::synchronise() 99 107 { 100 std::vector<Thread >::iterator it;108 std::vector<Thread*>::iterator it; 101 109 for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it ) 102 110 { 103 it->waitUntilFinished();111 (*it)->waitUntilFinished(); 104 112 } 105 113 }
Note: See TracChangeset
for help on using the changeset viewer.