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
b8e71625
authored
Apr 29, 2016
by
lucapegolotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
container_cpp: refactor BlockingContainer -> BlockingPushAndPopContainer, moved to internal folder
parent
ecd1ecdf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
142 deletions
+40
-142
containers_cpp/include/embb/containers/blocking_container.h
+0
-120
containers_cpp/include/embb/containers/blocking_priority_queue.h
+2
-2
containers_cpp/include/embb/containers/blocking_queue.h
+2
-2
containers_cpp/include/embb/containers/blocking_stack.h
+2
-2
containers_cpp/include/embb/containers/internal/blocking_push_and_pop_container.h
+30
-11
containers_cpp/include/embb/containers/internal/blocking_set-inl.h
+4
-5
No files found.
containers_cpp/include/embb/containers/blocking_container.h
deleted
100755 → 0
View file @
ecd1ecdf
/*
* 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_BLOCKING_CONTAINER_H_
#define EMBB_CONTAINERS_BLOCKING_CONTAINER_H_
#include <embb/base/base.h>
namespace
embb
{
namespace
containers
{
/*
* Abstract class to use for the implementation of blocking datastructure.
* Child classes need to be wrappers for another container.
*
* \tparam T Element type of the container's data.
*/
template
<
typename
Type
>
class
BlockingContainer
{
typedef
embb
::
base
::
Mutex
Mutex
;
protected
:
/*
* Mutex for thread synchronization.
*/
Mutex
mutex
;
/**
* Condition variable for notifying threads that are waiting
* for popping elements that new elements are available.
*/
embb
::
base
::
ConditionVariable
condition
;
/**
* Pure virtual method to be implemented in derived classes.
* The method must wrap the pushing method of the
* underlying container.
*/
virtual
void
SpecializedPush
(
const
Type
&
element
/**< [IN] Constant reference
to element that shall be pushed. */
)
=
0
;
/**
* Pure virtual method to be implemented in derived classes.
* The method must wrap the popping method of the
* underlying container.
*/
virtual
void
SpecializedPop
(
Type
&
element
/**< [IN, OUT] Reference to popped element*/
)
=
0
;
/**
* Pure virtual method to check if the underlying container
* is empty.
*
* \return \c true if container is empty, \c false otherwise.
*/
virtual
bool
IsEmpty
()
=
0
;
/**
* Pushes an element and notifies threads that are waiting to
* pop that new elements are available
*
*\note The calling threads acquire the mutex at the beginning
* and release it at the end of the method to avoid concurrent
* access to the structure.
*/
void
PushAndWakeUp
(
const
Type
&
element
/**< [IN] Constant reference
to element that shall be pushed */
);
/**
* Pops an element from the container. If no elements are
* available, the calling thread wait until it is notified
* by the condition variable in PushAndWakeUp.
*
*\note The calling threads acquire the mutex at the beginning
* and release it at the end of the method to avoid concurrent
* access to the structure.
*/
void
BlockingPop
(
Type
&
element
/**< [IN,OUT] Reference to popped element*/
);
};
}
}
#include <embb/containers/internal/blocking_container-inl.h>
#endif // EMBB_CONTAINERS_BLOCKING_CONTAINER_
\ No newline at end of file
containers_cpp/include/embb/containers/blocking_priority_queue.h
View file @
b8e71625
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include <queue>
#include <queue>
#include <embb/containers/
blocking
_container.h>
#include <embb/containers/
internal/blocking_push_and_pop
_container.h>
namespace
embb
{
namespace
embb
{
namespace
containers
{
namespace
containers
{
...
@@ -42,7 +42,7 @@ namespace containers {
...
@@ -42,7 +42,7 @@ namespace containers {
template
<
typename
Type
,
template
<
typename
Type
,
class
Container
=
std
::
vector
<
Type
>
,
class
Container
=
std
::
vector
<
Type
>
,
class
Compare
=
std
::
less
<
typename
Container
::
value_type
>>
class
Compare
=
std
::
less
<
typename
Container
::
value_type
>>
class
BlockingPriorityQueue
:
public
BlockingContainer
<
Type
>
{
class
BlockingPriorityQueue
:
public
Blocking
PushAndPop
Container
<
Type
>
{
private
:
private
:
/**
/**
...
...
containers_cpp/include/embb/containers/blocking_queue.h
View file @
b8e71625
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include <queue>
#include <queue>
#include <embb/containers/
blocking
_container.h>
#include <embb/containers/
internal/blocking_push_and_pop
_container.h>
namespace
embb
{
namespace
embb
{
namespace
containers
{
namespace
containers
{
...
@@ -40,7 +40,7 @@ namespace containers {
...
@@ -40,7 +40,7 @@ namespace containers {
* \tparam T Element type
* \tparam T Element type
*/
*/
template
<
typename
Type
>
template
<
typename
Type
>
class
BlockingQueue
:
public
BlockingContainer
<
Type
>
{
class
BlockingQueue
:
public
Blocking
PushAndPop
Container
<
Type
>
{
private
:
private
:
/**
/**
* Internal queue from the standard library.
* Internal queue from the standard library.
...
...
containers_cpp/include/embb/containers/blocking_stack.h
View file @
b8e71625
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include <stack>
#include <stack>
#include <embb/containers/
blocking
_container.h>
#include <embb/containers/
internal/blocking_push_and_pop
_container.h>
namespace
embb
{
namespace
embb
{
namespace
containers
{
namespace
containers
{
...
@@ -40,7 +40,7 @@ namespace containers {
...
@@ -40,7 +40,7 @@ namespace containers {
* \tparam T Element type
* \tparam T Element type
*/
*/
template
<
typename
Type
>
template
<
typename
Type
>
class
BlockingStack
:
public
BlockingContainer
<
Type
>
{
class
BlockingStack
:
public
Blocking
PushAndPop
Container
<
Type
>
{
private
:
private
:
/**
/**
* Internal stack from the standard library.
* Internal stack from the standard library.
...
...
containers_cpp/include/embb/containers/internal/blocking_
container-inl
.h
→
containers_cpp/include/embb/containers/internal/blocking_
push_and_pop_container
.h
View file @
b8e71625
#include "..\blocking_container.h"
/*
/*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
*
*
...
@@ -25,25 +24,42 @@
...
@@ -25,25 +24,42 @@
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
#ifndef EMBB_CONTAINERS_BLOCKING_
CONTAINER_INL
_H_
#ifndef EMBB_CONTAINERS_BLOCKING_
PUSH_AND_POP_CONTAINER
_H_
#define EMBB_CONTAINERS_BLOCKING_
CONTAINER_INL
_H_
#define EMBB_CONTAINERS_BLOCKING_
PUSH_AND_POP_CONTAINER
_H_
#include <embb/base/base.h>
namespace
embb
{
namespace
embb
{
namespace
containers
{
namespace
containers
{
template
<
typename
T
>
template
<
typename
Type
>
void
BlockingContainer
<
T
>::
PushAndWakeUp
(
const
T
&
element
)
{
class
BlockingPushAndPopContainer
{
typedef
embb
::
base
::
Mutex
Mutex
;
protected
:
Mutex
mutex
;
embb
::
base
::
ConditionVariable
condition
;
virtual
void
SpecializedPush
(
const
Type
&
element
)
=
0
;
virtual
void
SpecializedPop
(
Type
&
element
)
=
0
;
virtual
bool
IsEmpty
()
=
0
;
void
PushAndWakeUp
(
const
Type
&
element
)
{
embb
::
base
::
LockGuard
<
Mutex
>
lock
(
mutex
);
embb
::
base
::
LockGuard
<
Mutex
>
lock
(
mutex
);
SpecializedPush
(
element
);
SpecializedPush
(
element
);
condition
.
NotifyOne
();
condition
.
NotifyOne
();
}
}
template
<
typename
T
>
void
BlockingPop
(
Type
&
element
)
{
void
BlockingContainer
<
T
>::
BlockingPop
(
T
&
element
)
{
embb
::
base
::
UniqueLock
<
Mutex
>
lock
(
mutex
);
embb
::
base
::
UniqueLock
<
Mutex
>
lock
(
mutex
);
while
(
IsEmpty
())
{
while
(
IsEmpty
())
{
...
@@ -51,9 +67,12 @@ void BlockingContainer<T>::BlockingPop(T& element) {
...
@@ -51,9 +67,12 @@ void BlockingContainer<T>::BlockingPop(T& element) {
}
}
SpecializedPop
(
element
);
SpecializedPop
(
element
);
}
}
};
}
}
}
}
#endif // EMBB_CONTAINERS_BLOCKING_CONTAINER_INL_H_
#endif // EMBB_CONTAINERS_BLOCKING_PUSH_AND_POP_CONTAINER_
\ No newline at end of file
\ No newline at end of file
containers_cpp/include/embb/containers/internal/blocking_set-inl.h
View file @
b8e71625
#include "..\blocking_set.h"
/*
/*
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
* Copyright (c) 2014-2015, Siemens AG. All rights reserved.
*
*
...
@@ -25,8 +24,8 @@
...
@@ -25,8 +24,8 @@
* POSSIBILITY OF SUCH DAMAGE.
* POSSIBILITY OF SUCH DAMAGE.
*/
*/
#ifndef EMBB_CONTAINERS_BLOCKING_SET_INL_H_
#ifndef EMBB_CONTAINERS_
INTERNAL_
BLOCKING_SET_INL_H_
#define EMBB_CONTAINERS_BLOCKING_SET_INL_H_
#define EMBB_CONTAINERS_
INTERNAL_
BLOCKING_SET_INL_H_
namespace
embb
{
namespace
embb
{
...
@@ -57,4 +56,4 @@ namespace containers {
...
@@ -57,4 +56,4 @@ namespace containers {
}
}
}
}
#endif // EMBB_CONTAINERS_BLOCKING_SET_INL_H_
#endif // EMBB_CONTAINERS_INTERNAL_BLOCKING_SET_INL_H_
\ No newline at end of file
\ No newline at end of file
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