Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / PI_Malloc.h
blob804bdec0bf8226cfbf7778cb2c80b4339ed9498d
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file PI_Malloc.h
7 * @author Priyanka Gontla <pgontla@ece.uci.edu>
8 * @author Based on code that existed in other ACE files.
9 */
10 //==========================================================================
12 #ifndef ACE_PI_MALLOC_H
13 #define ACE_PI_MALLOC_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 (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
25 #include "ace/Malloc.h"
26 #include "ace/Based_Pointer_T.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 // prepare for position independent malloc
31 /**
32 * @class ACE_PI_Control_Block
34 * @brief This information is stored in memory allocated by the Memory_Pool.
36 * This class implements the control block structure that can be
37 * used in a "position independent" fashion, i.e., you don't need to
38 * "map" the underlying memory pool to the same address in
39 * processes sharing the memory. The trade off of this flexibility
40 * is more expensive malloc/free operations.
42 class ACE_Export ACE_PI_Control_Block
44 public:
45 class ACE_Malloc_Header;
46 class ACE_Name_Node;
48 typedef ACE_Based_Pointer<ACE_Malloc_Header> MALLOC_HEADER_PTR;
49 typedef ACE_Based_Pointer<ACE_Name_Node> NAME_NODE_PTR;
50 typedef ACE_Based_Pointer_Basic<char> CHAR_PTR;
52 /**
53 * @class ACE_Malloc_Header
55 * @brief This is the control block header. It's used by ACE_Malloc
56 * to keep track of each chunk of data when it's in the free
57 * list or in use.
59 class ACE_Export ACE_Malloc_Header
61 public:
62 ACE_Malloc_Header ();
64 /// Points to next block if on free list.
65 MALLOC_HEADER_PTR next_block_;
67 /// Initialize a malloc header pointer.
68 static void init_ptr (MALLOC_HEADER_PTR *ptr,
69 ACE_Malloc_Header *init,
70 void *base_addr);
72 /// Size of this header control block.
73 size_t size_;
75 # if !defined (ACE_PI_MALLOC_PADDING_SIZE)
76 # define ACE_PI_MALLOC_PADDING_SIZE ACE_MALLOC_ROUNDUP (ACE_MALLOC_HEADER_SIZE + sizeof (MALLOC_HEADER_PTR) + sizeof (size_t), ACE_MALLOC_ALIGN) - (sizeof (MALLOC_HEADER_PTR) + sizeof (size_t))
77 # endif /* !ACE_PI_MALLOC_PADDING_SIZE */
78 char padding_[(ACE_PI_MALLOC_PADDING_SIZE) ? ACE_PI_MALLOC_PADDING_SIZE : ACE_MALLOC_ALIGN];
80 /// Dump the state of the object.
81 void dump () const;
83 private:
84 // Disallow copy construction and assignment.
85 ACE_Malloc_Header (ACE_Malloc_Header const &);
86 void operator= (ACE_Malloc_Header const &);
89 /**
90 * @class ACE_Name_Node
92 * @brief This class supports "named memory regions" within ACE_Malloc.
94 * Internally, the named memory regions are stored as a
95 * doubly-linked list within the Memory_Pool. This makes
96 * it easy to iterate over the items in the list in both FIFO
97 * and LIFO order.
99 class ACE_Export ACE_Name_Node
101 public:
102 /// Constructor.
103 ACE_Name_Node (const char *name,
104 char *name_ptr,
105 char *pointer,
106 ACE_Name_Node *head);
108 /// Copy constructor.
109 ACE_Name_Node (const ACE_Name_Node &);
111 /// Constructor.
112 ACE_Name_Node ();
114 /// Constructor.
115 ~ACE_Name_Node ();
117 /// Initialize a name node pointer.
118 static void init_ptr (NAME_NODE_PTR *ptr,
119 ACE_Name_Node *init,
120 void *base_addr);
122 /// Return a pointer to the name of this node.
123 const char *name () const;
125 /// Assign a name;
126 void name (const char *);
128 /// Name of the Node.
129 CHAR_PTR name_;
131 /// Pointer to the contents.
132 CHAR_PTR pointer_;
134 /// Pointer to the next node in the doubly-linked list.
135 NAME_NODE_PTR next_;
137 /// Pointer to the previous node in the doubly-linked list.
138 NAME_NODE_PTR prev_;
140 /// Dump the state of the object.
141 void dump () const;
143 private:
144 // Disallow assignment.
145 void operator= (const ACE_Name_Node &);
148 /// Print out a bunch of size info for debugging.
149 static void print_alignment_info ();
151 /// Reference counter.
152 int ref_counter_;
154 /// Head of the linked list of Name Nodes.
155 NAME_NODE_PTR name_head_;
157 /// Current head of the freelist.
158 MALLOC_HEADER_PTR freep_;
160 /// Name of lock thats ensures mutual exclusion.
161 char lock_name_[MAXNAMELEN];
163 #if defined (ACE_HAS_MALLOC_STATS)
164 /// Keep statistics about ACE_Malloc state and performance.
165 ACE_Malloc_Stats malloc_stats_;
166 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
167 + sizeof (MALLOC_HEADER_PTR) \
168 + sizeof (int) \
169 + MAXNAMELEN \
170 + sizeof (ACE_Malloc_Stats)))
171 #else
172 #define ACE_PI_CONTROL_BLOCK_SIZE ((int)(sizeof (NAME_NODE_PTR) \
173 + sizeof (MALLOC_HEADER_PTR) \
174 + sizeof (int) \
175 + MAXNAMELEN))
176 #endif /* ACE_HAS_MALLOC_STATS */
178 # if !defined (ACE_PI_CONTROL_BLOCK_ALIGN_BYTES)
179 # define ACE_PI_CONTROL_BLOCK_ALIGN_BYTES \
180 ACE_MALLOC_ROUNDUP (ACE_PI_CONTROL_BLOCK_SIZE, ACE_MALLOC_ALIGN) - ACE_PI_CONTROL_BLOCK_SIZE
181 # endif /* !ACE_PI_CONTROL_BLOCK_ALIGN_LONGS */
182 /// Force alignment.
183 char align_[(ACE_PI_CONTROL_BLOCK_ALIGN_BYTES) ? ACE_PI_CONTROL_BLOCK_ALIGN_BYTES : ACE_MALLOC_ALIGN];
185 /// Dummy node used to anchor the freelist. This needs to come last...
186 ACE_Malloc_Header base_;
188 /// Dump the state of the object.
189 void dump () const;
191 private:
192 void operator= (const ACE_Control_Block &) = delete;
195 ACE_END_VERSIONED_NAMESPACE_DECL
197 #if defined (__ACE_INLINE__)
198 #include "ace/PI_Malloc.inl"
199 #endif /* __ACE_INLINE__ */
201 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
203 #include /**/ "ace/post.h"
205 #endif /* ACE_PI_MALLOC_H */