root/juggler/branches/1.0/SharedMem/vjMemPoolSGI.h

Revision 8789, 4.1 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34
35 #ifndef _MemPoolSGI_h_
36 #define _MemPoolSGI_h_
37 //----------------------------------------------
38 // vjMemPoolSGI
39 //
40 // Purpose:
41 //    Shared Memory pool on the SGI systems
42 //    Used by vjMemory (Base class) to control allocation
43 //    and deallocation from a "memory pool"
44 //
45 // Use:
46 //    Clients should create memory pools as needed
47 //    Then when objects are created, they can pass
48 //    a pool as a parameter to the new (if the object
49 //    is a derived from vjMemory)
50 //
51 // NOTE:
52 //    The static function 'init' MUST be called before
53 //    any forks or other process splitting take place.
54 //    This is because it sets static data that must
55 //    be shared across processes.
56 //
57 // Author:
58 //      Allen Bierbaum
59 //
60 // Date: 1-9-97
61 //-----------------------------------------------
62
63 #include <vjConfig.h>
64 #include <stdio.h>
65 #include <unistd.h>
66 #include <ulocks.h>
67 //#include <Kernel/vjDebug.h>
68
69 // - Call usinit in new processes created.  Try to overcome limitation on number of users.
70 // otherwise wet to a "big" number.
71
72
73 class vjMemPoolSGI : public vjMemPool
74 {
75 public:
76    vjMemPoolSGI(size_t initialSize = 65536, int numProcs = 8,
77                 char* staticTempName = "/var/tmp/memPoolSGIXXXXXX");
78
79    virtual ~vjMemPoolSGI() {
80       usdetach(arena);
81       unlink(arenaFileName);
82       std::cerr << "\nUnlinking: " << arenaFileName << std::endl;
83    }
84
85 public:
86    virtual void* allocate(size_t size)
87    {
88       void* retval;
89       retval = usmalloc(size, arena);
90
91       if (retval == NULL)
92          std::cerr << "MemPoolSGI: Out of memory!!!" << std::endl;
93
94       return retval;
95    }
96
97    virtual void deallocate(void* ptr)
98    {
99       usfree(ptr, arena);
100    }
101
102    virtual void* reallocate(void *ptr, size_t new_sz)
103    {
104       return usrealloc(ptr, new_sz, arena);
105    }
106
107 public:      // Non-virtual functions
108    usptr_t*    getArena() // Use with extreme caution  NOTE: Possibly use "friend" stuff
109    { return arena;}
110
111 public:
112    // Function must be called before any vjMemPools are created.
113    // Automatically called by the first new with default values if not called
114    // previously.
115    // Function to initialize any STATIC data structures.
116    static void init(size_t initialSize = 32768, int numProcs = 64,
117                     char* staticTempName = "/var/tmp/memPoolsArenaXXXXXX");
118
119    void* operator new(size_t sz)
120    {
121       std::cerr << "MemPoolSGI::new called. sz:" << sz << "\n";
122       if (arenaForMemPools == NULL)
123          init(); // Make sure that we are initialized already.
124
125       return usmalloc(sizeof(vjMemPoolSGI), arenaForMemPools);
126    }
127
128    void operator delete(void* ptr)
129    {
130       usfree(ptr, arenaForMemPools);
131    }
132
133 private:
134    usptr_t*   arena;
135    char*   arenaFileName;
136
137 private:    // Static data for all members -- Must be set before forks!!!!
138    static usptr_t* arenaForMemPools;
139    static char* arenaForMemPoolsFileName;
140 };
141
142 #endif
Note: See TracBrowser for help on using the browser.