Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e94b884a
authored
9 years ago
by
Christian Kern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for jira ticket #525
parent
56b4e070
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h
+35
-4
containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h
+14
-0
No files found.
containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h
View file @
e94b884a
...
...
@@ -213,11 +213,28 @@ LockFreeTreeValuePool(ForwardIterator first, ForwardIterator last) {
// Size of binary tree without the leaves
tree_size
=
size
-
1
;
// make sure, signed values are not negative
assert
(
tree_size
>=
0
);
assert
(
real_size
>=
0
);
size_t
tree_size_unsigned
=
static_cast
<
size_t
>
(
tree_size
);
size_t
real_size_unsigned
=
static_cast
<
size_t
>
(
real_size
);
// Pool stores elements of type T
pool
=
poolAllocator
.
allocate
(
static_cast
<
size_t
>
(
real_size
));
pool
=
poolAllocator
.
allocate
(
real_size_unsigned
);
// invoke inplace new for each pool element
for
(
size_t
i
=
0
;
i
!=
real_size_unsigned
;
++
i
)
{
new
(
&
pool
[
i
])
embb
::
base
::
Atomic
<
Type
>
();
}
// Tree holds the counter of not allocated elements
tree
=
treeAllocator
.
allocate
(
static_cast
<
size_t
>
(
tree_size
));
tree
=
treeAllocator
.
allocate
(
tree_size_unsigned
);
// invoke inplace new for each tree element
for
(
size_t
i
=
0
;
i
!=
tree_size_unsigned
;
++
i
)
{
new
(
&
tree
[
i
])
embb
::
base
::
Atomic
<
int
>
();
}
int
i
=
0
;
...
...
@@ -234,8 +251,22 @@ template<typename Type, Type Undefined, class PoolAllocator,
class
TreeAllocator
>
LockFreeTreeValuePool
<
Type
,
Undefined
,
PoolAllocator
,
TreeAllocator
>::
~
LockFreeTreeValuePool
()
{
poolAllocator
.
deallocate
(
pool
,
static_cast
<
size_t
>
(
real_size
));
treeAllocator
.
deallocate
(
tree
,
static_cast
<
size_t
>
(
tree_size
));
size_t
tree_size_unsigned
=
static_cast
<
size_t
>
(
tree_size
);
size_t
real_size_unsigned
=
static_cast
<
size_t
>
(
real_size
);
poolAllocator
.
deallocate
(
pool
,
real_size_unsigned
);
// invoke destructor for each pool element
for
(
size_t
i
=
0
;
i
!=
real_size_unsigned
;
++
i
)
{
pool
[
i
].
~
Atomic
();
}
treeAllocator
.
deallocate
(
tree
,
tree_size_unsigned
);
// invoke destructor for each tree element
for
(
size_t
i
=
0
;
i
!=
tree_size_unsigned
;
++
i
)
{
tree
[
i
].
~
Atomic
();
}
}
}
// namespace containers
...
...
This diff is collapsed.
Click to expand it.
containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h
View file @
e94b884a
...
...
@@ -66,9 +66,17 @@ WaitFreeArrayValuePool(ForwardIterator first, ForwardIterator last) {
size
=
static_cast
<
int
>
(
dist
);
// conversion may result in negative number. check!
assert
(
size
>=
0
);
// Use the allocator to allocate an array of size dist
pool
=
allocator
.
allocate
(
dist
);
// invoke inplace new for each pool element
for
(
size_t
i
=
0
;
i
!=
dist
;
++
i
)
{
new
(
&
pool
[
i
])
embb
::
base
::
Atomic
<
Type
>
();
}
int
i
=
0
;
// Store the elements of the range
...
...
@@ -79,6 +87,12 @@ WaitFreeArrayValuePool(ForwardIterator first, ForwardIterator last) {
template
<
typename
Type
,
Type
Undefined
,
class
Allocator
>
WaitFreeArrayValuePool
<
Type
,
Undefined
,
Allocator
>::~
WaitFreeArrayValuePool
()
{
// invoke destructor for each pool element
for
(
int
i
=
0
;
i
!=
size
;
++
i
)
{
pool
[
i
].
~
Atomic
();
}
// free memory
allocator
.
deallocate
(
pool
,
(
size_t
)
size
);
}
}
// namespace containers
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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