Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 28, 2009, 3:04:30 PM (15 years ago)
Author:
scheusso
Message:

a lot of cleanup
some bugfixes (Thread, ThreadPool)
the biggest part of the network (~80% cpu time) is now multithreaded (1 thread for each client)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp6/src/core/ThreadPool.cc

    r3231 r3240  
    2828
    2929#include "ThreadPool.h"
     30#include "Thread.h"
    3031#include <cassert>
    3132
     
    3940    ThreadPool::~ThreadPool()
    4041    {
     42        unsigned int a = this->setNrOfThreads(0);
     43        assert(a == 0);
    4144    }
    4245   
     
    4447    {
    4548        for( unsigned int i=0; i<nr; i++ )
    46             this->threadPool_.push_back(Thread());
     49            this->threadPool_.push_back(new Thread());
    4750    }
    4851    unsigned int ThreadPool::removeThreads( unsigned int nr )
    4952    {
    5053        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; )
    5356        {
    54             if( ! it->isWorking() )
     57            if( ! (*it)->isWorking() )
    5558            {
    56                 this->threadPool_.erase( it++ );
     59                Thread* temp = *it;
     60                it=this->threadPool_.erase( it );
     61                delete temp;
    5762                ++i;
    5863            }
     64            else
     65              ++it;
    5966        }
    6067        return i;
     
    7481    }
    7582   
    76     bool ThreadPool::passFunction( Functor* functor, bool addThread )
     83    bool ThreadPool::passFunction( Executor* executor, bool addThread )
    7784    {
    78         std::vector<Thread>::iterator it;
     85        std::vector<Thread*>::iterator it;
    7986        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
    8087        {
    81             if ( ! it->isWorking() )
     88            if ( ! (*it)->isWorking() )
    8289            {
    83                 bool b = it->evaluateFunctor( functor );
     90                bool b = (*it)->evaluateExecutor( executor );
    8491                assert(b); // if b is false then there is some code error
    8592                return true;
     
    8996        {
    9097            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);
    92100            return true;
    93101        }
     
    98106    void ThreadPool::synchronise()
    99107    {
    100         std::vector<Thread>::iterator it;
     108        std::vector<Thread*>::iterator it;
    101109        for ( it=this->threadPool_.begin(); it!=this->threadPool_.end(); ++it )
    102110        {
    103             it->waitUntilFinished();
     111            (*it)->waitUntilFinished();
    104112        }
    105113    }
Note: See TracChangeset for help on using the changeset viewer.