00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #include <PsnBarrier.h> 00019 #include <iostream> 00020 #ifdef _SPROC 00021 char *PsnBarrier::nomfich="/tmp/barXXXXXX"; 00022 usptr_t *PsnBarrier::handle=usinit(mktemp(nomfich)); 00023 #endif 00024 00025 PsnBarrier::PsnBarrier(int nbProc) : 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 } 00046 00047 PsnBarrier::~PsnBarrier() 00048 { 00049 #ifdef _SPROC 00050 free_barrier( _barriere ); 00051 #else 00052 pthread_mutex_destroy(&_mylock); 00053 pthread_cond_destroy(&_cond); 00054 #endif 00055 } 00056 00057 void PsnBarrier::Sync() { 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 } 00087 00088
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |