MemPoolSGI.cpp

Go to the documentation of this file.
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-01 11:48:13 -0600 (Sat, 01 Jan 2005) $
00011  * Version:       $Revision: 16520 $
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 #include <vpr/vprConfig.h>
00043 
00044 #include <vpr/md/SPROC/SharedMem/MemPool.h>
00045 
00046 
00047 usptr_t* vpr::MemPoolSGI::arenaForMemPools      = NULL;
00048 char* vpr::MemPoolSGI::arenaForMemPoolsFileName = NULL;
00049 
00050 
00051 vpr::MemPoolSGI::MemPoolSGI (size_t initialSize, int numProcs,
00052                              char* staticTempName)
00053 {
00054    std::cerr.setf(std::ios::showbase);
00055    std::cerr << "\nMemPoolSGI: Allocating arena (" << initialSize << " bytes, "
00056              << numProcs  << " procs, " << std::hex  << this << std::dec
00057              << ")\n" << std::flush;
00058 
00059    usconfig(CONF_INITUSERS, numProcs);
00060    usconfig(CONF_INITSIZE, initialSize);
00061    usconfig(CONF_AUTOGROW, 1);   // Default, but we set anyway
00062 //#ifdef DEBUG_VJ
00063    usconfig(CONF_LOCKTYPE, US_DEBUGPLUS);    // what type of lock information
00064 //#endif
00065 
00066    //static char* staticTempName = "/var/tmp/memPoolSGIXXXXXX";  // Do it this way because mktemp overwrite's the variable
00067    char* tempName = new char[strlen(staticTempName)+1];      // Therefore we need to use a non-static variable
00068    strcpy(tempName, staticTempName);
00069 
00070    arena = usinit(mktemp(tempName));   // Allocate the arena
00071 
00072    arenaFileName = tempName;      // So we know where the file is
00073    //delete tempName;           // Delete the temporary file name
00074 
00075    if ( arena == NULL )
00076    {
00077       perror("ERROR: PoolSGI::MemPoolSGI");
00078    }
00079 
00080    std::cerr << "  " << arenaFileName << ", " << "arena: " << std::hex << arena
00081              << std::dec << std::endl;
00082    std::cerr.unsetf(std::ios::showbase);
00083 }
00084 
00085 void vpr::MemPoolSGI::init (size_t initialSize, int numProcs,
00086                             char* staticTempName)
00087 {
00088    if ( arenaForMemPools == NULL )
00089    {
00090       std::cerr << "\nMemPoolSGI: Allocating Base Arena for ALL MemPoolSGI's.\n"
00091                 << initialSize << " bytes, " << numProcs << " procs"
00092                 << "\n" << std::flush;
00093 
00094       usconfig(CONF_INITUSERS, numProcs);
00095       usconfig(CONF_INITSIZE, initialSize);
00096       usconfig(CONF_AUTOGROW, 1);   // Default, but we set anyway
00097 
00098       char* tempName = strdup (staticTempName); // make mutable copy for mktemp
00099 
00100       arenaForMemPools = usinit(mktemp(tempName));
00101       unlink(tempName);
00102 
00103       if ( arenaForMemPools == NULL )
00104       {
00105          perror("ERROR: MemPoolSGI::init. Was not able to get an arena!!!!");
00106       }
00107       arenaForMemPoolsFileName = (char*)usmalloc(strlen(staticTempName)+1, arenaForMemPools);
00108       strcpy(arenaForMemPoolsFileName, tempName);
00109       free (tempName);
00110 
00111       std::cerr.setf(std::ios::showbase);
00112       std::cerr << "  " << arenaForMemPoolsFileName << ", " << "arena: "
00113                 << std::hex << arenaForMemPools << std::dec << std::endl;
00114       std::cerr.unsetf(std::ios::showbase);
00115    }
00116    else
00117    {
00118       std::cerr << "Tried to re-init the Base Arena for ALL MemPoolSGI's"
00119                 << std::endl;
00120    }
00121 }

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1