Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
de6e68cf
Commit
de6e68cf
authored
May 13, 2013
by
Mukund Sivaraman
Browse files
[2850] Fix MemorySegmentMapped::allMemoryDeallocated() and make it non-const
parent
3c98ade5
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/lib/util/memory_segment.h
View file @
de6e68cf
...
...
@@ -157,7 +157,7 @@ public:
/// \return Returns <code>true</code> if all allocated memory (including
/// names associated by memory addresses by \c setNamedAddress()) was
/// deallocated, <code>false</code> otherwise.
virtual
bool
allMemoryDeallocated
()
const
=
0
;
virtual
bool
allMemoryDeallocated
()
=
0
;
/// \brief Associate specified address in the segment with a given name.
///
...
...
src/lib/util/memory_segment_local.cc
View file @
de6e68cf
...
...
@@ -47,7 +47,7 @@ MemorySegmentLocal::deallocate(void* ptr, size_t size) {
}
bool
MemorySegmentLocal
::
allMemoryDeallocated
()
const
{
MemorySegmentLocal
::
allMemoryDeallocated
()
{
return
(
allocated_size_
==
0
&&
named_addrs_
.
empty
());
}
...
...
src/lib/util/memory_segment_local.h
View file @
de6e68cf
...
...
@@ -64,7 +64,7 @@ public:
///
/// \return Returns <code>true</code> if all allocated memory was
/// deallocated, <code>false</code> otherwise.
virtual
bool
allMemoryDeallocated
()
const
;
virtual
bool
allMemoryDeallocated
();
/// \brief Local segment version of getNamedAddress.
///
...
...
src/lib/util/memory_segment_mapped.cc
View file @
de6e68cf
...
...
@@ -139,11 +139,22 @@ struct MemorySegmentMapped::Impl {
void
reserveMemory
()
{
if
(
!
read_only_
)
{
// Reserve a named address for use during setNamedAddress().
const
offset_ptr
<
void
>*
reserved_storage
=
base_sgmt_
->
find_or_construct
<
offset_ptr
<
void
>
>
(
RESERVED_NAMED_ADDRESS_STORAGE_NAME
,
std
::
nothrow
)();
assert
(
reserved_storage
);
// Reserve a named address for use during
// setNamedAddress(). Though this will almost always succeed
// during construction, it may fail later during a call from
// allMemoryDeallocated() when the segment has been in use
// for a while.
while
(
true
)
{
const
offset_ptr
<
void
>*
reserved_storage
=
base_sgmt_
->
find_or_construct
<
offset_ptr
<
void
>
>
(
RESERVED_NAMED_ADDRESS_STORAGE_NAME
,
std
::
nothrow
)();
if
(
reserved_storage
)
{
break
;
}
growSegment
();
}
}
}
...
...
@@ -306,8 +317,12 @@ MemorySegmentMapped::deallocate(void* ptr, size_t) {
}
bool
MemorySegmentMapped
::
allMemoryDeallocated
()
const
{
return
(
impl_
->
base_sgmt_
->
all_memory_deallocated
());
MemorySegmentMapped
::
allMemoryDeallocated
()
{
impl_
->
freeReservedMemory
();
const
bool
result
=
impl_
->
base_sgmt_
->
all_memory_deallocated
();
impl_
->
reserveMemory
();
return
(
result
);
}
MemorySegment
::
NamedAddressResult
...
...
src/lib/util/memory_segment_mapped.h
View file @
de6e68cf
...
...
@@ -175,7 +175,7 @@ public:
/// read-only mode; in that case MemorySegmentError will be thrown.
virtual
void
deallocate
(
void
*
ptr
,
size_t
size
);
virtual
bool
allMemoryDeallocated
()
const
;
virtual
bool
allMemoryDeallocated
();
/// \brief Mapped segment version of setNamedAddress.
///
...
...
src/lib/util/tests/memory_segment_mapped_unittest.cc
View file @
de6e68cf
...
...
@@ -467,7 +467,14 @@ TEST_F(MemorySegmentMappedTest, shrink) {
EXPECT_EQ
(
shrinked_size
,
segment_
->
getSize
());
// Check that the segment is still usable after shrink.
void
*
p
=
segment_
->
allocate
(
sizeof
(
uint32_t
));
void
*
p
=
NULL
;
while
(
!
p
)
{
try
{
p
=
segment_
->
allocate
(
sizeof
(
uint32_t
));
}
catch
(
const
MemorySegmentGrown
&
)
{
// Do nothing. Just try again.
}
}
segment_
->
deallocate
(
p
,
sizeof
(
uint32_t
));
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment