vpr::MemPoolSGI Class Reference

Shared Memory pool on the SGI systems, used primarily for semaphores and mutexes. More...

#include <vpr/md/SPROC/SharedMem/MemPoolSGI.h>

Inheritance diagram for vpr::MemPoolSGI:

Inheritance graph
[legend]
Collaboration diagram for vpr::MemPoolSGI:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MemPoolSGI (size_t initialSize=65536, int numProcs=8, char *staticTempName="/var/tmp/memPoolSGIXXXXXX")
virtual ~MemPoolSGI ()
virtual void * allocate (size_t size)
virtual void deallocate (void *ptr)
virtual void * reallocate (void *ptr, size_t new_sz)
usptr_t * getArena ()
 Use with extreme caution.
void * operator new (size_t sz)
void operator delete (void *ptr)

Static Public Member Functions

static void init (size_t initialSize=32768, int numProcs=64, char *staticTempName="/var/tmp/memPoolsArenaXXXXXX")
 Function must be called before any vpr::MemPools are created.

Detailed Description

Shared Memory pool on the SGI systems, used primarily for semaphores and mutexes.

Used to control allocation and deallocation from a "memory pool."

This class is for use exclusively within VPR. More specifically, it is only for use by the SPROC threading subsystem.

Clients should create memory pools as needed. Then, when objects are created, they can pass a pool as a parameter to the new (if the object is a derived from vprMemory).

Note:
The static function init() MUST be called before any forks or other process splitting take place. This is because it sets static data that must be shared across processes.
Date:
January 9, 1997

Definition at line 76 of file MemPoolSGI.h.


Constructor & Destructor Documentation

vpr::MemPoolSGI::MemPoolSGI ( size_t  initialSize = 65536,
int  numProcs = 8,
char *  staticTempName = "/var/tmp/memPoolSGIXXXXXX" 
)

Definition at line 51 of file MemPoolSGI.cpp.

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 }

virtual vpr::MemPoolSGI::~MemPoolSGI (  )  [inline, virtual]

Definition at line 82 of file MemPoolSGI.h.

00083    {
00084       usdetach(arena);
00085       unlink(arenaFileName);
00086       std::cerr << "\nUnlinking: " << arenaFileName << std::endl;
00087    }


Member Function Documentation

virtual void* vpr::MemPoolSGI::allocate ( size_t  size  )  [inline, virtual]

Implements vpr::MemPool.

Definition at line 90 of file MemPoolSGI.h.

Referenced by vpr::BarrierSGI::BarrierSGI(), vpr::MutexSGI::MutexSGI(), and vpr::SemaphoreSGI::SemaphoreSGI().

00091    {
00092       void* retval;
00093       retval = usmalloc(size, arena);
00094 
00095       if ( retval == NULL )
00096       {
00097          std::cerr << "MemPoolSGI: Out of memory!!!" << std::endl;
00098       }
00099 
00100       return retval;
00101    }

virtual void vpr::MemPoolSGI::deallocate ( void *  ptr  )  [inline, virtual]

Implements vpr::MemPool.

Definition at line 103 of file MemPoolSGI.h.

Referenced by vpr::BarrierSGI::~BarrierSGI(), vpr::MutexSGI::~MutexSGI(), and vpr::SemaphoreSGI::~SemaphoreSGI().

00104    {
00105       usfree(ptr, arena);
00106    }

virtual void* vpr::MemPoolSGI::reallocate ( void *  ptr,
size_t  new_sz 
) [inline, virtual]

Implements vpr::MemPool.

Definition at line 108 of file MemPoolSGI.h.

00109    {
00110       return usrealloc(ptr, new_sz, arena);
00111    }

usptr_t* vpr::MemPoolSGI::getArena (  )  [inline]

Use with extreme caution.

Note:
Possibly use "friend" stuff.

Definition at line 118 of file MemPoolSGI.h.

Referenced by vpr::BarrierSGI::BarrierSGI(), vpr::MutexSGI::MutexSGI(), vpr::SemaphoreSGI::SemaphoreSGI(), vpr::MutexSGI::~MutexSGI(), and vpr::SemaphoreSGI::~SemaphoreSGI().

00119    {
00120       return arena;
00121    }

void vpr::MemPoolSGI::init ( size_t  initialSize = 32768,
int  numProcs = 64,
char *  staticTempName = "/var/tmp/memPoolsArenaXXXXXX" 
) [static]

Function must be called before any vpr::MemPools are created.

Automatically called by the first new with default values if not called previously. Function to initialize any STATIC data structures.

Definition at line 85 of file MemPoolSGI.cpp.

Referenced by operator new().

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 }

void* vpr::MemPoolSGI::operator new ( size_t  sz  )  [inline]

Definition at line 133 of file MemPoolSGI.h.

References init().

00134    {
00135       std::cerr << "MemPoolSGI::new called. sz:" << sz << "\n";
00136       if ( arenaForMemPools == NULL )
00137       {
00138          init(); // Make sure that we are initialized already.
00139       }
00140 
00141       return usmalloc(sizeof(MemPoolSGI), arenaForMemPools);
00142    }

void vpr::MemPoolSGI::operator delete ( void *  ptr  )  [inline]

Definition at line 144 of file MemPoolSGI.h.

00145    {
00146       usfree(ptr, arenaForMemPools);
00147    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:45 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1