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
16ccb48e
authored
Mar 19, 2015
by
Tobias Fuchs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
containers_cpp: moved internal::FixedSizeList into own header definition
parent
6d3c6d03
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
251 additions
and
172 deletions
+251
-172
containers_cpp/include/embb/containers/internal/fixed_size_list-inl.h
+103
-0
containers_cpp/include/embb/containers/internal/fixed_size_list.h
+147
-0
containers_cpp/include/embb/containers/internal/hazard_pointer-inl.h
+0
-65
containers_cpp/include/embb/containers/internal/hazard_pointer.h
+1
-107
No files found.
containers_cpp/include/embb/containers/internal/fixed_size_list-inl.h
0 → 100644
View file @
16ccb48e
/*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_INL_H_
#define EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_INL_H_
namespace
embb
{
namespace
containers
{
namespace
internal
{
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>::
FixedSizeList
(
size_t
max_size
)
:
max_size
(
max_size
),
size
(
0
)
{
elementsArray
=
static_cast
<
ElementT
*>
(
embb
::
base
::
Allocation
::
Allocate
(
sizeof
(
ElementT
)
*
max_size
));
}
template
<
typename
ElementT
>
inline
size_t
FixedSizeList
<
ElementT
>::
GetSize
()
const
{
return
size
;
}
template
<
typename
ElementT
>
inline
size_t
FixedSizeList
<
ElementT
>::
GetMaxSize
()
const
{
return
max_size
;
}
template
<
typename
ElementT
>
inline
void
FixedSizeList
<
ElementT
>::
clear
()
{
size
=
0
;
}
template
<
typename
ElementT
>
typename
FixedSizeList
<
ElementT
>::
iterator
FixedSizeList
<
ElementT
>::
begin
()
const
{
return
&
elementsArray
[
0
];
}
template
<
typename
ElementT
>
typename
FixedSizeList
<
ElementT
>::
iterator
FixedSizeList
<
ElementT
>::
end
()
const
{
return
&
elementsArray
[
size
];
}
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>
&
FixedSizeList
<
ElementT
>::
operator
=
(
const
FixedSizeList
&
other
)
{
size
=
0
;
if
(
max_size
<
other
.
size
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Copy target to small"
);
}
for
(
const_iterator
it
=
other
.
begin
();
it
!=
other
.
end
();
++
it
)
{
PushBack
(
*
it
);
}
return
*
this
;
}
template
<
typename
ElementT
>
bool
FixedSizeList
<
ElementT
>::
PushBack
(
ElementT
const
el
)
{
if
(
size
+
1
>
max_size
)
{
return
false
;
}
elementsArray
[
size
]
=
el
;
size
++
;
return
true
;
}
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>::~
FixedSizeList
()
{
embb
::
base
::
Allocation
::
Free
(
elementsArray
);
}
}
// namespace internal
}
// namespace containers
}
// namespace embb
#endif // EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_INL_H_
containers_cpp/include/embb/containers/internal/fixed_size_list.h
0 → 100644
View file @
16ccb48e
/*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_H_
#define EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_H_
namespace
embb
{
namespace
containers
{
namespace
internal
{
/**
* A list with fixed size, implemented as an array. Replaces std::vector that
* was used in previous hazard pointer implementation.
*
* Provides iterators, so we can apply algorithms from the STL.
*
* \tparam ElementT Type of the elements contained in the list.
*/
template
<
typename
ElementT
>
class
FixedSizeList
{
private
:
/**
* Capacity of the list
*/
size_t
max_size
;
/**
* Size of the list
*/
size_t
size
;
/**
* Pointer to the array containing the list
*/
ElementT
*
elementsArray
;
/**
* Copy constructor not implemented. Would require dynamic memory allocation.
*/
FixedSizeList
(
const
FixedSizeList
&
/**< [IN] Other list */
);
public
:
/**
* Definition of an iterator
*/
typedef
ElementT
*
iterator
;
/**
* Definition of a const iterator
*/
typedef
const
ElementT
*
const_iterator
;
/**
* Constructor, initializes list with given capacity
*/
FixedSizeList
(
size_t
max_size
/**< [IN] Capacity of the list */
);
/**
* Gets the current size of the list
*
* \return Size of the list
*/
inline
size_t
GetSize
()
const
;
/**
* Gets the capacity of the list
*
* \return The capacity of the list
*/
inline
size_t
GetMaxSize
()
const
;
/**
* Removes all elements from the list without changing the capacity
*/
inline
void
clear
();
/**
* Iterator pointing to the first element
*
* \return Begin iterator
*/
iterator
begin
()
const
;
/**
* Iterator pointing beyond the last element
*
* \return End iterator
*/
iterator
end
()
const
;
/**
* Copies the elements of another list to this list. The capacity of
* this list has to be greater than or equal to the size of the other list.
*/
FixedSizeList
&
operator
=
(
const
FixedSizeList
&
other
/**< [IN] Other list */
);
/**
* Appends an element to the end of the list
*
* \return \c false if the operation was not successful because the list is
* full, otherwise \c true.
*/
bool
PushBack
(
ElementT
const
el
/**< [IN] Element to append to the list */
);
/**
* Destructs the list.
*/
~
FixedSizeList
();
};
}
// namespace internal
}
// namespace containers
}
// namespace embb
#include "./fixed_size_list-inl.h"
#endif // EMBB_CONTAINERS_INTERNAL_FIXED_SIZE_LIST_H_
containers_cpp/include/embb/containers/internal/hazard_pointer-inl.h
View file @
16ccb48e
...
...
@@ -30,71 +30,6 @@
namespace
embb
{
namespace
containers
{
namespace
internal
{
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>::
FixedSizeList
(
size_t
max_size
)
:
max_size
(
max_size
),
size
(
0
)
{
elementsArray
=
static_cast
<
ElementT
*>
(
embb
::
base
::
Allocation
::
Allocate
(
sizeof
(
ElementT
)
*
max_size
));
}
template
<
typename
ElementT
>
inline
size_t
FixedSizeList
<
ElementT
>::
GetSize
()
const
{
return
size
;
}
template
<
typename
ElementT
>
inline
size_t
FixedSizeList
<
ElementT
>::
GetMaxSize
()
const
{
return
max_size
;
}
template
<
typename
ElementT
>
inline
void
FixedSizeList
<
ElementT
>::
clear
()
{
size
=
0
;
}
template
<
typename
ElementT
>
typename
FixedSizeList
<
ElementT
>::
iterator
FixedSizeList
<
ElementT
>::
begin
()
const
{
return
&
elementsArray
[
0
];
}
template
<
typename
ElementT
>
typename
FixedSizeList
<
ElementT
>::
iterator
FixedSizeList
<
ElementT
>::
end
()
const
{
return
&
elementsArray
[
size
];
}
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>
&
FixedSizeList
<
ElementT
>::
operator
=
(
const
FixedSizeList
&
other
)
{
size
=
0
;
if
(
max_size
<
other
.
size
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Copy target to small"
);
}
for
(
const_iterator
it
=
other
.
begin
();
it
!=
other
.
end
();
++
it
)
{
PushBack
(
*
it
);
}
return
*
this
;
}
template
<
typename
ElementT
>
bool
FixedSizeList
<
ElementT
>::
PushBack
(
ElementT
const
el
)
{
if
(
size
+
1
>
max_size
)
{
return
false
;
}
elementsArray
[
size
]
=
el
;
size
++
;
return
true
;
}
template
<
typename
ElementT
>
FixedSizeList
<
ElementT
>::~
FixedSizeList
()
{
embb
::
base
::
Allocation
::
Free
(
elementsArray
);
}
template
<
typename
GuardType
>
bool
HazardPointerThreadEntry
<
GuardType
>::
IsActive
()
{
...
...
containers_cpp/include/embb/containers/internal/hazard_pointer.h
View file @
16ccb48e
...
...
@@ -31,6 +31,7 @@
#include <embb/base/thread_specific_storage.h>
#include <embb/base/thread.h>
#include <embb/containers/wait_free_array_value_pool.h>
#include <embb/containers/internal/fixed_size_list.h>
#include <embb/base/function.h>
#include <algorithm>
...
...
@@ -43,113 +44,6 @@
namespace
embb
{
namespace
containers
{
namespace
internal
{
/**
* A list with fixed size, implemented as an array. Replaces std::vector that
* was used in previous hazard pointer implementation.
*
* Provides iterators, so we can apply algorithms from the STL.
*
* \tparam ElementT Type of the elements contained in the list.
*/
template
<
typename
ElementT
>
class
FixedSizeList
{
private
:
/**
* Capacity of the list
*/
size_t
max_size
;
/**
* Size of the list
*/
size_t
size
;
/**
* Pointer to the array containing the list
*/
ElementT
*
elementsArray
;
/**
* Copy constructor not implemented. Would require dynamic memory allocation.
*/
FixedSizeList
(
const
FixedSizeList
&
/**< [IN] Other list */
);
public
:
/**
* Definition of an iterator
*/
typedef
ElementT
*
iterator
;
/**
* Definition of a const iterator
*/
typedef
const
ElementT
*
const_iterator
;
/**
* Constructor, initializes list with given capacity
*/
FixedSizeList
(
size_t
max_size
/**< [IN] Capacity of the list */
);
/**
* Gets the current size of the list
*
* \return Size of the list
*/
inline
size_t
GetSize
()
const
;
/**
* Gets the capacity of the list
*
* \return The capacity of the list
*/
inline
size_t
GetMaxSize
()
const
;
/**
* Removes all elements from the list without changing the capacity
*/
inline
void
clear
();
/**
* Iterator pointing to the first element
*
* \return Begin iterator
*/
iterator
begin
()
const
;
/**
* Iterator pointing beyond the last element
*
* \return End iterator
*/
iterator
end
()
const
;
/**
* Copies the elements of another list to this list. The capacity of
* this list has to be greater than or equal to the size of the other list.
*/
FixedSizeList
&
operator
=
(
const
FixedSizeList
&
other
/**< [IN] Other list */
);
/**
* Appends an element to the end of the list
*
* \return \c false if the operation was not successful because the list is
* full, otherwise \c true.
*/
bool
PushBack
(
ElementT
const
el
/**< [IN] Element to append to the list */
);
/**
* Destructs the list.
*/
~
FixedSizeList
();
};
/**
* Hazard pointer entry for a single thread. Holds the actual guards that
...
...
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