Changeset 21043

Show
Ignore:
Timestamp:
02/23/08 08:24:22 (7 months ago)
Author:
patrick
Message:

Fixed yet more coding standard violations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/vpr/Thread/ThreadPool.cpp

    r21042 r21043  
    6565// --------------------------------------------------------------------------- 
    6666ThreadPool::ThreadPool(const int numToStartWith) 
    67    : readyThreads(0) 
     67   : mReadyThreads(0) 
    6868{ 
    6969   //DebugLock.acquire(); 
     
    7575   //DebugLock.release(); 
    7676 
    77    listHead = NULL; 
    78    workingCount = 0; 
    79    listLock.release();             // release threadList 
    80    finishedLock.release();         // Initialize if to threads being done 
     77   mListHead = NULL; 
     78   mWorkingCount = 0; 
     79   mListLock.release();             // release threadList 
     80   mFinishedLock.release();         // Initialize if to threads being done 
    8181 
    8282   //-- Start the initial # of threads ---// 
     
    8989ThreadPool::~ThreadPool() 
    9090{ 
    91    OneThread* cur_thread = listHead; 
     91   OneThread* cur_thread = mListHead; 
    9292   while ( cur_thread != NULL ) 
    9393   { 
     
    115115      << "[vpr::ThreadPool::threadLoop()] Entering." << std::endl 
    116116      << vprDEBUG_FLUSH; 
    117 //      vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) << Thread::self() 
    118 //      << " vpr::ThreadPool::threadLoop: theThreadAsVoid:" 
     117//      vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) 
     118//      << "[vpr::ThreadPool::threadLoop()] theThreadAsVoid:" 
    119119//      << theThreadAsVoid << endl << vprDEBUG_FLUSH; 
    120120//   DebugLock.release(); 
    121121 
    122    listLock.acquire(); 
    123    listLock.release();     // Do this to make sure addThread is done 
     122   mListLock.acquire(); 
     123   mListLock.release();     // Do this to make sure addThread is done 
    124124 
    125125   for ( ;; ) 
     
    129129      // ASSERT:  We now have work to do... 
    130130      // --- PROCESS ENTRY OVERHEAD --- // 
    131       workingCountLock.acquire();     // Get access to the working thread count 
    132       if ( workingCount == 0 ) 
     131      mWorkingCountLock.acquire();     // Get access to the working thread count 
     132      if ( mWorkingCount == 0 ) 
    133133      { 
    134          finishedLock.acquire();       // Now there are threads working 
     134         mFinishedLock.acquire();       // Now there are threads working 
    135135      } 
    136       ++workingCount;                  // Update thread count 
    137       workingCountLock.release(); 
     136      ++mWorkingCount;                  // Update thread count 
     137      mWorkingCountLock.release(); 
    138138 
    139139      // --- DO THE WORK --- // 
     
    141141 
    142142      // --- PROCESS EXIT OVERHEAD --- // 
    143       workingCountLock.acquire();     // Get access to the working count 
    144       --workingCount; 
    145       if ( workingCount == 0 ) 
     143      mWorkingCountLock.acquire();     // Get access to the working count 
     144      --mWorkingCount; 
     145      if ( mWorkingCount == 0 ) 
    146146      { 
    147          finishedLock.release();       // Now there are no threads working 
     147         mFinishedLock.release();       // Now there are no threads working 
    148148      } 
    149       workingCountLock.release(); 
     149      mWorkingCountLock.release(); 
    150150   } 
    151151} 
     
    157157void ThreadPool::threadSleep(OneThread* theThread) 
    158158{ 
    159    listLock.acquire();               // acquire exclusive rights to threadList 
    160    theThread->next = listHead;   // put self on head of the list 
    161    listHead = theThread; 
    162    listLock.release();               // release threadList 
    163  
    164    readyThreads.release();           // notify master, at least 1 on the list 
     159   mListLock.acquire();              // acquire exclusive rights to threadList 
     160   theThread->next = mListHead;      // put self on head of the list 
     161   mListHead = theThread; 
     162   mListLock.release();              // release threadList 
     163 
     164   mReadyThreads.release();          // notify master, at least 1 on the list 
    165165 
    166166   theThread->threadWait.acquire();  // sleep until master needs/releases me 
     
    174174OneThread* ThreadPool::getThread() 
    175175{ 
    176    OneThread* theThread; 
    177  
    178    readyThreads.acquire();           // wait until at least 1 thread is free 
    179  
    180    listLock.acquire();               // acquire exclusive rights to threadList 
    181    theThread = listHead;         // get address of first free OneThread 
    182    listHead = theThread->next;   // make next in list, the head of list 
    183    listLock.release();               // release threadList 
    184  
    185    return theThread; 
     176   OneThread* the_thread; 
     177 
     178   mReadyThreads.acquire();        // wait until at least 1 thread is free 
     179 
     180   mListLock.acquire();            // acquire exclusive rights to threadList 
     181   the_thread = mListHead;         // get address of first free OneThread 
     182   mListHead = the_thread->next;   // make next in list, the head of list 
     183   mListLock.release();            // release threadList 
     184 
     185   return the_thread; 
    186186} 
    187187 
     
    190190void ThreadPool::printList() const 
    191191{ 
    192    OneThread* curThread = listHead
    193    int counter = 0
     192   OneThread* cur_thread(mListHead)
     193   int counter(0)
    194194 
    195195   std::cerr << "----- Thread List -----\n"; 
    196196 
    197    while ( curThread != NULL ) 
     197   while ( cur_thread != NULL ) 
    198198   { 
    199199      std::cerr << "Thread: " << counter++ << std::endl; 
    200       std::cerr << "\tpid: " << *curThread << std::endl; 
    201       curThread = curThread->next; 
     200      std::cerr << "\tpid: " << *cur_thread << std::endl; 
     201      cur_thread = cur_thread->next; 
    202202   } 
    203203} 
     
    214214//    DebugLock.release(); 
    215215 
    216    Guard<Mutex> guard(listLock);   // Protect the head 
     216   Guard<Mutex> guard(mListLock);   // Protect the head 
    217217 
    218218   //OneThread* newThread = new (this->getMyMemPool()->allocate(sizeof(OneThread))) OneThread;    // Used placement new 
     
    229229//    DebugLock.release(); 
    230230 
    231    return listHead; 
     231   return mListHead; 
    232232} 
    233233 
  • juggler/trunk/modules/vapor/vpr/Thread/ThreadPool.h

    r21042 r21043  
    133133   void wait() 
    134134   { 
    135       finishedLock.acquire();      // Get the lock that means threads done 
    136       finishedLock.release();      // Reset it to done 
     135      mFinishedLock.acquire();      // Get the lock that means threads done 
     136      mFinishedLock.release();      // Reset it to done 
    137137   } 
    138138 
     
    140140 
    141141private: 
    142    Semaphore readyThreads;    /**< Count represents threads ready to work */ 
    143    Mutex listLock;            /**< Mutex control of threadList head */ 
    144    Mutex workingCountLock;    /**< Mutex on thread count */ 
    145    Mutex finishedLock;        /**< Lock for wether thread are finished, lock -> doing work */ 
    146    OneThread* listHead;       /**< First ready vpr::OneThread */ 
    147    volatile int workingCount; /**< Number of threads currently doing work */ 
     142   Semaphore mReadyThreads;    /**< Count represents threads ready to work */ 
     143   Mutex mListLock;            /**< Mutex control of threadList head */ 
     144   Mutex mWorkingCountLock;    /**< Mutex on thread count */ 
     145   Mutex mFinishedLock;        /**< Lock for wether thread are finished, lock -> doing work */ 
     146   OneThread* mListHead;       /**< First ready vpr::OneThread */ 
     147   volatile int mWorkingCount; /**< Number of threads currently doing work */ 
    148148}; 
    149149