Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnBarrier Class Reference

a barrier for threads. More...

#include <PsnBarrier.h>

List of all members.

Public Methods

 PsnBarrier (const int nbproc)
 constructor

 ~PsnBarrier ()
 Destructor.

void Sync ()
 Sync wait for all threads to call this synchronisation barrier.


Protected Attributes

int _count
 number of threads having called sync

int _nbThreads
 number of threads waited for

pthread_mutex_t _mylock
pthread_cond_t _cond


Detailed Description

a barrier for threads.

Author:
D.Margery (for C++ wrapping). Original C code by R.Lottiaux
Version:
1.0

Definition at line 33 of file PsnBarrier.h.


Constructor & Destructor Documentation

PsnBarrier::PsnBarrier const int    nbproc
 

constructor

Parameters:
int number of threads to wait for

Definition at line 25 of file PsnBarrier.cxx.

References _cond, and _mylock.

00025                                  :
00026    _count ( 1 ),
00027    _nbThreads ( nbProc )
00028  {
00029 #ifdef _SPROC
00030   if (_handle == NULL) 
00031      {
00032         perror("PsnBarrier :: constructeur :: Impossible de créer le usptr nécessaire");
00033         exit(1);
00034      }
00035   _barriere = new_barrier( _handle );
00036   if(_barriere == NULL) 
00037      {
00038         perror("PsnBarrier :: constructeur :: impossible de créer une nouvelle barrière");
00039         exit(1);
00040      }
00041 #else
00042   pthread_mutex_init ( &_mylock , NULL ) ;
00043   pthread_cond_init ( &_cond , NULL ) ;
00044 #endif
00045 }

PsnBarrier::~PsnBarrier  
 

Destructor.

Definition at line 47 of file PsnBarrier.cxx.

References _cond, and _mylock.

00048 {
00049 #ifdef _SPROC
00050   free_barrier( _barriere );
00051 #else
00052   pthread_mutex_destroy(&_mylock);
00053   pthread_cond_destroy(&_cond);
00054 #endif
00055 }


Member Function Documentation

void PsnBarrier::Sync  
 

Sync wait for all threads to call this synchronisation barrier.

Definition at line 57 of file PsnBarrier.cxx.

References _cond, _count, _mylock, and _nbThreads.

Referenced by PsnMultiThreadedScheduler::run(), PsnMultiThreadedBenchmarkingScheduler::run(), PsnMultiThreadedBenchedScheduler::run(), PsnMultiThreadedScheduler::runStep(), and PsnMultiThreadedBenchmarkingScheduler::runStep().

00057                       {
00058 #ifdef _SPROC
00059   barrier(_barriere,_nbThreads);
00060 #ifdef _DEBUG
00061   cout<<"une syncronisation"<<endl;
00062 #endif
00063 #else
00064 #ifdef _DEBUGLOCK
00065   cout<<"PsnBarrier::"<<this<<"::"<<pthread_self()<<"::Sync()";
00066 #endif
00067   pthread_mutex_lock ( &_mylock ) ;
00068   if (_count < _nbThreads)
00069     {
00070       _count++;
00071       pthread_cond_wait ( &_cond,
00072                           &_mylock ) ;
00073 
00074       pthread_mutex_unlock ( &_mylock ) ;
00075     }
00076   else
00077     {
00078       pthread_mutex_unlock ( &_mylock ) ;
00079       _count = 1;
00080       pthread_cond_broadcast ( &_cond ) ;
00081     }
00082 #ifdef _DEBUGLOCK
00083   cerr<<" passée par "<<pthread_self()<<endl;
00084 #endif
00085 #endif
00086 }


Member Data Documentation

pthread_cond_t PsnBarrier::_cond [protected]
 

Definition at line 67 of file PsnBarrier.h.

Referenced by PsnBarrier(), Sync(), and ~PsnBarrier().

int PsnBarrier::_count [protected]
 

number of threads having called sync

Definition at line 56 of file PsnBarrier.h.

Referenced by Sync().

pthread_mutex_t PsnBarrier::_mylock [protected]
 

Definition at line 66 of file PsnBarrier.h.

Referenced by PsnBarrier(), Sync(), and ~PsnBarrier().

int PsnBarrier::_nbThreads [protected]
 

number of threads waited for

Definition at line 59 of file PsnBarrier.h.

Referenced by Sync().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:25:52 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001