1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Sbrk_Memory_Pool.h"
3 #include "ace/Log_Category.h"
4 #include "ace/Malloc_Base.h"
7 #if !defined (ACE_LACKS_SBRK)
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_ALLOC_HOOK_DEFINE(ACE_Sbrk_Memory_Pool
)
13 // Ask system for more local memory via sbrk(2).
16 ACE_Sbrk_Memory_Pool::acquire (size_t nbytes
,
17 size_t &rounded_bytes
)
19 ACE_TRACE ("ACE_Sbrk_Memory_Pool::acquire");
20 rounded_bytes
= this->round_up (nbytes
);
21 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) acquiring more chunks, nbytes = %d, rounded_bytes = %d\n"), nbytes, rounded_bytes));
22 void *cp
= ACE_OS::sbrk (rounded_bytes
);
25 ACELIB_ERROR_RETURN ((LM_ERROR
,
30 // ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) acquired more chunks, nbytes = %d, rounded_bytes = %d, new break = %u\n"), nbytes, rounded_bytes, cp));
34 /* No-op for now... */
37 ACE_Sbrk_Memory_Pool::release (int)
39 ACE_TRACE ("ACE_Sbrk_Memory_Pool::release");
44 ACE_Sbrk_Memory_Pool::sync (ssize_t
, int)
46 ACE_TRACE ("ACE_Sbrk_Memory_Pool::sync");
51 ACE_Sbrk_Memory_Pool::sync (void *, size_t, int)
53 ACE_TRACE ("ACE_Sbrk_Memory_Pool::sync");
58 ACE_Sbrk_Memory_Pool::protect (ssize_t
, int)
60 ACE_TRACE ("ACE_Sbrk_Memory_Pool::protect");
65 ACE_Sbrk_Memory_Pool::protect (void *, size_t, int)
67 ACE_TRACE ("ACE_Sbrk_Memory_Pool::protect");
71 // Ask system for initial chunk of local memory.
74 ACE_Sbrk_Memory_Pool::init_acquire (size_t nbytes
,
75 size_t &rounded_bytes
,
78 ACE_TRACE ("ACE_Sbrk_Memory_Pool::init_acquire");
79 // Note that we assume that when ACE_Sbrk_Memory_Pool is used,
80 // ACE_Malloc's constructor will only get called once. If this
81 // assumption doesn't hold, we are in deep trouble!
84 return this->acquire (nbytes
, rounded_bytes
);
88 ACE_Sbrk_Memory_Pool::dump () const
90 #if defined (ACE_HAS_DUMP)
91 ACE_TRACE ("ACE_Sbrk_Memory_Pool::dump");
92 #endif /* ACE_HAS_DUMP */
95 ACE_Sbrk_Memory_Pool::ACE_Sbrk_Memory_Pool (const ACE_TCHAR
*,
98 ACE_TRACE ("ACE_Sbrk_Memory_Pool::ACE_Sbrk_Memory_Pool");
101 ACE_Sbrk_Memory_Pool::~ACE_Sbrk_Memory_Pool ()
106 ACE_Sbrk_Memory_Pool::base_addr () const
111 // Round up the request to a multiple of the page size.
114 ACE_Sbrk_Memory_Pool::round_up (size_t nbytes
)
116 ACE_TRACE ("ACE_Sbrk_Memory_Pool::round_up");
117 return ACE::round_to_pagesize (nbytes
);
120 ACE_END_VERSIONED_NAMESPACE_DECL
122 #endif /* !ACE_LACKS_SBRK */