00001 /****************** <VPR heading BEGIN do not edit this line> ***************** 00002 * 00003 * VR Juggler Portable Runtime 00004 * 00005 * Original Authors: 00006 * Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira 00007 * 00008 * ----------------------------------------------------------------- 00009 * File: $RCSfile: Barrier.h,v $ 00010 * Date modified: $Date: 2004/01/28 21:52:09 $ 00011 * Version: $Revision: 1.11 $ 00012 * ----------------------------------------------------------------- 00013 * 00014 ****************** <VPR heading END do not edit this line> ******************/ 00015 00016 /*************** <auto-copyright.pl BEGIN do not edit this line> ************** 00017 * 00018 * VR Juggler is (C) Copyright 1998-2003 by Iowa State University 00019 * 00020 * Original Authors: 00021 * Allen Bierbaum, Christopher Just, 00022 * Patrick Hartling, Kevin Meinert, 00023 * Carolina Cruz-Neira, Albert Baker 00024 * 00025 * This library is free software; you can redistribute it and/or 00026 * modify it under the terms of the GNU Library General Public 00027 * License as published by the Free Software Foundation; either 00028 * version 2 of the License, or (at your option) any later version. 00029 * 00030 * This library is distributed in the hope that it will be useful, 00031 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00032 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00033 * Library General Public License for more details. 00034 * 00035 * You should have received a copy of the GNU Library General Public 00036 * License along with this library; if not, write to the 00037 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00038 * Boston, MA 02111-1307, USA. 00039 * 00040 *************** <auto-copyright.pl END do not edit this line> ***************/ 00041 00042 #ifndef _VPR_Barrier_h_ 00043 #define _VPR_Barrier_h_ 00044 00045 #include <vpr/vprConfig.h> 00046 00047 #if VPR_THREAD_DOMAIN_INCLUDE == VPR_DOMAIN_IRIX_SPROC 00048 # include <ulocks.h> 00049 # include <vpr/md/SPROC/Sync/BarrierSGI.h> 00050 #elif (VPR_THREAD_DOMAIN_INCLUDE == VPR_DOMAIN_NSPR) || \ 00051 (VPR_THREAD_DOMAIN_INCLUDE == VPR_DOMAIN_POSIX) 00052 # include <vpr/Sync/CondVar.h> 00053 # include <vpr/Sync/Mutex.h> 00054 # include <vpr/Sync/Guard.h> 00055 00056 00057 namespace vpr 00058 { 00059 00063 class SubBarrier 00064 { 00065 public: 00069 SubBarrier (int count, Mutex* lock) 00070 : barrierFinished(lock), runningThreads(count) 00071 { 00072 } 00073 00074 CondVar barrierFinished; 00075 00076 int runningThreads; 00077 }; 00078 00090 class Barrier 00091 { 00092 public: 00096 Barrier (int count) 00097 : currentGeneration(0), count(count), subBarrier1(count, &mutex), 00098 subBarrier2(count, &mutex) 00099 { 00100 //std::cerr << "vpr::Barrier::Barrier: Entering." << std::endl; 00101 subBarrier[0] = &subBarrier1; 00102 subBarrier[1] = &subBarrier2; 00103 } 00104 00109 int wait(void); 00110 00115 void addProcess() 00116 { 00117 std::cerr << "vpr::Barrier::addProcess: Not implemented yet." 00118 << std::endl; 00119 } 00120 00125 void removeProcess() 00126 { 00127 std::cerr << "vpr::Barrier::removeProcess: Not implemented yet." 00128 << std::endl; 00129 } 00130 00131 private: 00132 Mutex mutex; 00138 int currentGeneration; 00139 00140 00141 int count; 00143 SubBarrier subBarrier1; 00144 SubBarrier subBarrier2; 00145 SubBarrier* subBarrier[2]; 00146 // We keep two <sub_barriers>, one for the first "generation" of 00147 // waiters, and one for the next "generation" of waiters. This 00148 // efficiently solves the problem of what to do if all the first 00149 // generation waiters don't leave the barrier before one of the 00150 // threads calls wait() again (i.e., starts up the next generation 00151 // barrier). 00152 00153 // = Prevent assignment and initialization. 00154 void operator= (const Barrier &) 00155 { 00156 ; 00157 } 00158 00159 Barrier (const Barrier &) 00160 : subBarrier1(0, &mutex), subBarrier2(0, &mutex) 00161 { 00162 ; 00163 } 00164 }; 00165 00166 } // End of vpr namespace 00167 00168 #endif /* ! VPR_USE_IRIX_SPROC */ 00169 00170 #endif /* _VPR_Barrier_h_ */
1.2.14 written by Dimitri van Heesch,
© 1997-2002