Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Pagefile_Memory_Pool.h
blob4e8d4af8315b4a79c64c8314bde9e3cbc993d374
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Pagefile_Memory_Pool.h
7 * @author Dougls C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Prashant Jain <pjain@cs.wustl.edu>
9 */
10 //=============================================================================
12 #ifndef ACE_PAGEFILE_MEMORY_POOL_H
13 #define ACE_PAGEFILE_MEMORY_POOL_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #if defined (ACE_WIN32)
25 #include "ace/ACE.h"
26 #include "ace/os_include/sys/os_mman.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /**
31 * @class ACE_Pagefile_Memory_Pool_Options
33 * @brief Helper class for Pagefile Memory Pool constructor options.
35 * This should be a nested class, but that breaks too many
36 * compilers.
38 class ACE_Export ACE_Pagefile_Memory_Pool_Options
40 public:
41 /// Initialization method.
42 ACE_Pagefile_Memory_Pool_Options (
43 void *base_addr = ACE_DEFAULT_PAGEFILE_POOL_BASE,
44 size_t max_size = ACE_DEFAULT_PAGEFILE_POOL_SIZE);
46 /// Base address of the memory-mapped backing store.
47 void *base_addr_;
49 /// Maximum size the pool may grow.
50 size_t max_size_;
53 /**
54 * @class ACE_Pagefile_Memory_Pool
56 * @brief Make a memory pool that is based on "anonymous" memory
57 * regions allocated from the Win32 page file.
59 class ACE_Export ACE_Pagefile_Memory_Pool
61 public:
62 typedef ACE_Pagefile_Memory_Pool_Options OPTIONS;
64 /// Initialize the pool.
65 ACE_Pagefile_Memory_Pool (const ACE_TCHAR *backing_store_name = 0,
66 const OPTIONS *options = 0);
68 /// Destructor
69 virtual ~ACE_Pagefile_Memory_Pool () = default;
71 /// Ask system for initial chunk of shared memory.
72 void *init_acquire (size_t nbytes,
73 size_t &rounded_bytes,
74 int &first_time);
76 /// Acquire at least @a nbytes from the memory pool. <rounded_bytes>
77 /// is the actual number of bytes allocated.
78 void *acquire (size_t nbytes,
79 size_t &rounded_bytes);
81 /// Instruct the memory pool to release all of its resources.
82 int release (int destroy = 1);
84 /**
85 * Win32 Structural exception selector. The return value decides
86 * how to handle memory pool related structural exceptions. Returns
87 * 1, 0, or , -1.
89 virtual int seh_selector (void *);
91 /**
92 * Try to extend the virtual address space so that @a addr is now
93 * covered by the address mapping. The method succeeds and returns
94 * 0 if the backing store has adequate memory to cover this address.
95 * Otherwise, it returns -1. This method is typically called by an
96 * exception handler for a Win32 structured exception when another
97 * process has grown the backing store (and its mapping) and our
98 * process now incurs a fault because our mapping isn't in range
99 * (yet).
101 int remap (void *addr);
103 /// Round up to system page size.
104 size_t round_to_page_size (size_t nbytes);
106 /// Round up to the chunk size required by the operation system
107 size_t round_to_chunk_size (size_t nbytes);
109 // = Don't need this methods here ...
110 int sync (ssize_t = -1, int = MS_SYNC);
111 int sync (void *, size_t, int = MS_SYNC);
112 int protect (ssize_t = -1, int = PROT_RDWR);
113 int protect (void *, size_t, int = PROT_RDWR);
115 /// Return the base address of this memory pool, 0 if base_addr
116 /// never changes.
117 virtual void *base_addr () const;
119 void dump () const {}
121 protected:
123 * Map portions or the entire pool into the local virtual address
124 * space. To do this, we compute the new @c file_offset of the
125 * backing store and commit the memory.
127 int map (int &firstTime, size_t appendBytes = 0);
129 /// Release the mapping.
130 int unmap ();
132 private:
134 * @class Control_Block
136 * @brief Attributes that are meaningful in local storage only.
138 class Control_Block
140 public:
141 /// Required base address
142 void *req_base_;
144 /// Base address returned from system call
145 void *mapped_base_;
148 * @class Shared_Control_Block
150 * @brief Pool statistics
152 class Shared_Control_Block
154 public:
155 /// Maximum size the pool may grow
156 size_t max_size_;
158 /// Size of mapped shared memory segment
159 size_t mapped_size_;
161 /// Offset to mapped but not yet acquired address space
162 ptrdiff_t free_offset_;
164 /// Size of mapped but not yet acquired address space
165 size_t free_size_;
168 Shared_Control_Block sh_;
171 // Base of mapped region. If this has the value of 0 then the OS is
172 // free to select any address to map the file, otherwise this value
173 // is what the OS must try to use to mmap the file.
175 /// Description of what our process mapped.
176 Control_Block local_cb_;
178 /// Shared memory pool statistics.
179 Control_Block *shared_cb_;
181 /// File mapping handle.
182 ACE_HANDLE object_handle_;
184 /// System page size.
185 size_t page_size_;
187 /// Name of the backing store where the shared memory pool is kept.
188 ACE_TCHAR backing_store_name_[MAXPATHLEN];
191 ACE_END_VERSIONED_NAMESPACE_DECL
193 #endif /* ACE_WIN32 */
195 #if defined (__ACE_INLINE__)
196 #include "ace/Pagefile_Memory_Pool.inl"
197 #endif /* __ACE_INLINE__ */
199 #include /**/ "ace/post.h"
200 #endif /* ACE_MEMORY_POOL_H */