root/juggler/tags/1.0.5/SharedMem/vjMemPoolSGI.h

Revision 2828, 4.1 kB (checked in by patrickh, 8 years ago)

Updated the copyright to what ISU's lawyers decided they want now.
The vast majority of this was done using Kevin's auto-copyright.pl script
which definitely made this easier. All the copyright blocks now have
begin and end tags so that if and when we have to update the copyright
information again, it will be even simpler.

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