Changeset 3297

Show
Ignore:
Timestamp:
08/17/04 16:34:58 (10 years ago)
Author:
sspicer
Message:

Added Barrier::release(), Barrier::numThreadsCurrentlyBlocked().

Location:
OpenThreads/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenThreads/trunk/include/OpenThreads/Barrier

    r2132 r3297  
    6363    virtual void block(unsigned int numThreads=0); 
    6464 
     65    /** 
     66     *  Release the barrier, now. 
     67     */ 
     68    virtual void release(); 
     69 
     70    /** 
     71     *  Return the number of threads currently blocked in the barrier, 
     72     *  Return -1 if error. 
     73     */  
     74    virtual int numThreadsCurrentlyBlocked(); 
     75     
    6576private: 
    6677 
  • OpenThreads/trunk/pthread_src/PThreadBarrier.c++

    r2043 r3297  
    4444//---------------------------------------------------------------------------- 
    4545// 
    46 // Decription: Constructor 
     46// Description: Constructor 
    4747// 
    4848// Use: public. 
     
    118118//---------------------------------------------------------------------------- 
    119119// 
    120 // Decription: Destructor 
     120// Description: Destructor 
    121121// 
    122122// Use: public. 
     
    137137//---------------------------------------------------------------------------- 
    138138// 
    139 // Decription: Reset the barrier to its original state 
     139// Description: Reset the barrier to its original state 
    140140// 
    141141// Use: public. 
     
    153153//---------------------------------------------------------------------------- 
    154154// 
    155 // Decription: Block until numThreads threads have entered the barrier. 
     155// Description: Block until numThreads threads have entered the barrier. 
    156156// 
    157157// Use: public. 
     
    189189 
    190190} 
     191 
     192//---------------------------------------------------------------------------- 
     193// 
     194// Description: Release the barrier, now. 
     195// 
     196// Use: public. 
     197// 
     198void Barrier::release() { 
     199 
     200    PThreadBarrierPrivateData *pd = 
     201        static_cast<PThreadBarrierPrivateData*>(_prvData); 
     202 
     203    int my_phase; 
     204 
     205    pthread_mutex_lock(&(pd->lock)); 
     206    my_phase = pd->phase; 
     207     
     208    pd->cnt = 0;                         // reset for next use 
     209    pd->phase = 1 - my_phase;            // toggle phase 
     210    pthread_cond_broadcast(&(pd->cond)); 
     211    pthread_mutex_unlock(&(pd->lock)); 
     212 
     213} 
     214 
     215//---------------------------------------------------------------------------- 
     216// 
     217// Description: Return the number of threads currently blocked in the barrier 
     218// 
     219// Use: public 
     220// 
     221int Barrier::numThreadsCurrentlyBlocked() { 
     222     
     223    PThreadBarrierPrivateData *pd = 
     224        static_cast<PThreadBarrierPrivateData*>(_prvData); 
     225     
     226     
     227    int numBlocked = -1; 
     228    pthread_mutex_lock(&(pd->lock)); 
     229    numBlocked = pd->cnt; 
     230    pthread_mutex_unlock(&(pd->lock)); 
     231 
     232    return numBlocked; 
     233} 
  • OpenThreads/trunk/sproc_src/SprocBarrier.c++

    r2359 r3297  
    181181 
    182182} 
     183 
     184//---------------------------------------------------------------------------- 
     185// 
     186// Description: Release the barrier, now. 
     187// 
     188// Use: public. 
     189// 
     190void Barrier::release() { 
     191 
     192    SprocBarrierPrivateData *pd = 
     193        static_cast<SprocBarrierPrivateData*>(_prvData); 
     194 
     195#ifdef USE_IRIX_NATIVE_BARRIER 
     196 
     197    printf("ERROR >>>>> Barrier::release() cannot be implemented using native IRIX Barriers !!!\n"); 
     198 
     199#else 
     200 
     201    int my_phase; 
     202    pd->_mutex.lock(); 
     203     
     204    my_phase = pd->phase; 
     205     
     206    pd->cnt = 0;                         // reset for next use 
     207    pd->phase = 1 - my_phase;            // toggle phase 
     208    pd->_cond.broadcast(); 
     209 
     210    pd->_mutex.unlock(); 
     211 
     212#endif 
     213 
     214} 
     215 
     216//---------------------------------------------------------------------------- 
     217// 
     218// Description: Return the number of threads currently blocked in the barrier 
     219// 
     220// Use: public 
     221// 
     222int Barrier::numThreadsCurrentlyBlocked() { 
     223     
     224    SprocBarrierPrivateData *pd = 
     225        static_cast<SprocBarrierPrivateData*>(_prvData); 
     226 
     227    int numBlocked = -1; 
     228    pd->_mutex.lock(); 
     229    numBlocked = pd->cnt; 
     230    pd->_cond.broadcast(); 
     231    return numBlocked; 
     232 
     233} 
  • OpenThreads/trunk/win32_src/Win32ThreadBarrier.cpp

    r2200 r3297  
    9696        } 
    9797} 
     98 
     99//---------------------------------------------------------------------------- 
     100// 
     101// Description: Release the barrier, now. 
     102// 
     103// Use: public. 
     104// 
     105void Barrier::release() { 
     106 
     107    Win32BarrierPrivateData *pd = 
     108        static_cast<Win32BarrierPrivateData*>(_prvData); 
     109 
     110    int my_phase; 
     111 
     112    ScopedLock<Mutex> lock(pd->lock); 
     113    my_phase = pd->phase; 
     114     
     115    pd->cnt = 0;                         // reset for next use 
     116    pd->phase = 1 - my_phase;            // toggle phase 
     117    pd->cond.broadcast(); 
     118     
     119 
     120} 
     121 
     122//---------------------------------------------------------------------------- 
     123// 
     124// Description: Return the number of threads currently blocked in the barrier 
     125// 
     126// Use: public 
     127// 
     128int Barrier::numThreadsCurrentlyBlocked() { 
     129     
     130    Win32BarrierPrivateData *pd = 
     131        static_cast<Win32BarrierPrivateData*>(_prvData); 
     132 
     133    int numBlocked = -1; 
     134    ScopedLock<Mutex> lock(pd->lock); 
     135    numBlocked = pd->cnt; 
     136    ScopedLock<Mutex> unlock(pd->lock); 
     137    return numBlocked; 
     138 
     139}