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$ 00010 * Date modified: $Date: 2005-01-17 22:34:01 -0600 (Mon, 17 Jan 2005) $ 00011 * Version: $Revision: 16635 $ 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-2005 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 00063 class BarrierSGI 00064 { 00065 public: 00069 BarrierSGI(int count) : syncCount(count) 00070 { 00071 if (barrierPool == NULL) 00072 { 00073 barrierPool = new MemPoolSGI(65536, 32, 00074 "/var/tmp/memBarrierPoolSGIXXXXXX"); 00075 attachedCounter = static_cast<int*>(barrierPool->allocate(sizeof(int))); 00076 *attachedCounter = 0; 00077 } 00078 *attachedCounter = *attachedCounter + 1; // Track how many mutexes are allocated 00079 //vprDEBUG << "BarrierSGI::BarrierSGI: attachedCounter: " << *attachedCounter << std::endl << vprDEBUG_FLUSH; 00080 00081 // ----- Allocate the mutex ----- // 00082 theBarrier = new_barrier(barrierPool->getArena()); 00083 } 00084 00085 ~BarrierSGI() 00086 { 00087 // ---- Delete the barrier --- // 00088 free_barrier(theBarrier); 00089 00090 // ---- Deal with the pool --- // 00091 *attachedCounter = *attachedCounter - 1; // Track how many mutexes are allocated 00092 00093 //vprDEBUG << "BarrierSGI::~BarrierSGI: attachedCounter: " << *attachedCounter << std::endl << vprDEBUG_FLUSH; 00094 00095 if (*attachedCounter == 0) 00096 { 00097 barrierPool->deallocate(attachedCounter); 00098 attachedCounter = NULL; 00099 delete barrierPool; 00100 barrierPool = NULL; 00101 } 00102 } 00103 00108 int wait(int numProcs) 00109 { 00110 return -1; 00111 } 00112 00113 int wait() 00114 { 00115 barrier(theBarrier, syncCount); 00116 //init_barrier(theBarrier); // -- How do I reset the barrier -- // 00117 return 0; 00118 } 00119 00124 void addProcess() 00125 { 00126 Guard<Mutex> guard(mutex); 00127 syncCount++; 00128 } 00129 00134 void removeProcess() 00135 { 00136 Guard<Mutex> guard(mutex); 00137 syncCount--; 00138 } 00139 00140 void setProcesses(int procs) 00141 { 00142 Guard<Mutex> guard(mutex); 00143 syncCount = procs; 00144 } 00145 00146 protected: 00147 Mutex mutex; 00148 int syncCount; 00149 barrier_t* theBarrier; 00150 00151 // = Prevent assignment and initialization. 00152 void operator=(const BarrierSGI &) {;} 00153 BarrierSGI(const BarrierSGI &) {;} 00154 00155 static MemPoolSGI* barrierPool; 00156 static int* attachedCounter; 00157 }; 00158 00159 } // End of vpr namespace 00160 00161 #endif
1.5.1