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: BarrierSGI.h,v $ 00010 * Date modified: $Date: 2004/01/28 21:44:08 $ 00011 * Version: $Revision: 1.9 $ 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 _vprBarrierSGI_h_ 00043 #define _vprBarrierSGI_h_ 00044 00045 #include <vpr/vprConfig.h> 00046 #include <ulocks.h> 00047 #include <vpr/md/SPROC/SharedMem/MemPool.h> 00048 #include <vpr/Sync/Mutex.h> 00049 #include <vpr/Sync/Guard.h> 00050 00051 00052 namespace vpr 00053 { 00054 00062 class BarrierSGI 00063 { 00064 public: 00068 BarrierSGI (int count) : syncCount(count) 00069 { 00070 if (barrierPool == NULL) 00071 { 00072 barrierPool = new MemPoolSGI(65536, 32, 00073 "/var/tmp/memBarrierPoolSGIXXXXXX"); 00074 attachedCounter = static_cast<int*>(barrierPool->allocate(sizeof(int))); 00075 *attachedCounter = 0; 00076 } 00077 *attachedCounter = *attachedCounter + 1; // Track how many mutexes are allocated 00078 //vprDEBUG << "BarrierSGI::BarrierSGI: attachedCounter: " << *attachedCounter << std::endl << vprDEBUG_FLUSH; 00079 00080 // ----- Allocate the mutex ----- // 00081 theBarrier = new_barrier(barrierPool->getArena()); 00082 } 00083 00084 ~BarrierSGI() 00085 { 00086 // ---- Delete the barrier --- // 00087 free_barrier(theBarrier); 00088 00089 // ---- Deal with the pool --- // 00090 *attachedCounter = *attachedCounter - 1; // Track how many mutexes are allocated 00091 00092 //vprDEBUG << "BarrierSGI::~BarrierSGI: attachedCounter: " << *attachedCounter << std::endl << vprDEBUG_FLUSH; 00093 00094 if (*attachedCounter == 0) 00095 { 00096 barrierPool->deallocate(attachedCounter); 00097 attachedCounter = NULL; 00098 delete barrierPool; 00099 barrierPool = NULL; 00100 } 00101 } 00102 00107 int wait(int numProcs) 00108 { 00109 return -1; 00110 } 00111 00112 int wait () 00113 { 00114 barrier(theBarrier, syncCount); 00115 //init_barrier(theBarrier); // -- How do I reset the barrier -- // 00116 return 0; 00117 } 00118 00123 void addProcess() 00124 { 00125 Guard<Mutex> guard(mutex); 00126 syncCount++; 00127 } 00128 00133 void removeProcess() 00134 { 00135 Guard<Mutex> guard(mutex); 00136 syncCount--; 00137 } 00138 00139 void setProcesses(int procs) 00140 { 00141 Guard<Mutex> guard(mutex); 00142 syncCount = procs; 00143 } 00144 00145 protected: 00146 Mutex mutex; 00147 int syncCount; 00148 barrier_t* theBarrier; 00149 00150 // = Prevent assignment and initialization. 00151 void operator= (const BarrierSGI &) {} 00152 BarrierSGI (const BarrierSGI &) {} 00153 00154 static MemPoolSGI* barrierPool; 00155 static int* attachedCounter; 00156 }; 00157 00158 } // End of vpr namespace 00159 00160 #endif
1.2.14 written by Dimitri van Heesch,
© 1997-2002