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
0e87c034
authored
9 years ago
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dataflow_cpp: fixed memory leaks
parent
5563ddbd
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
18 deletions
+82
-18
dataflow_cpp/include/embb/dataflow/internal/in.h
+6
-0
dataflow_cpp/include/embb/dataflow/internal/inputs.h
+30
-5
dataflow_cpp/include/embb/dataflow/internal/process.h
+7
-0
dataflow_cpp/include/embb/dataflow/internal/sink.h
+8
-1
dataflow_cpp/include/embb/dataflow/network.h
+28
-11
dataflow_cpp/test/dataflow_cpp_test_simple.cc
+3
-1
No files found.
dataflow_cpp/include/embb/dataflow/internal/in.h
View file @
0e87c034
...
...
@@ -51,6 +51,12 @@ class In {
In
()
:
values_
(
NULL
),
connected_
(
false
),
slices_
(
0
)
{}
~
In
()
{
if
(
NULL
!=
values_
)
{
embb
::
base
::
Allocation
::
Free
(
values_
);
}
}
SignalType
const
&
GetSignal
(
int
clock
)
const
{
return
values_
[
clock
%
slices_
];
}
...
...
This diff is collapsed.
Click to expand it.
dataflow_cpp/include/embb/dataflow/internal/inputs.h
View file @
0e87c034
...
...
@@ -67,9 +67,14 @@ class Inputs<T1, embb::base::internal::Nil, embb::base::internal::Nil,
embb
::
base
::
internal
::
Nil
>
,
public
ClockListener
{
public
:
Inputs
()
{
Inputs
()
:
count_
(
NULL
)
{
test_count_
=
1
;
}
~
Inputs
()
{
if
(
NULL
!=
count_
)
{
embb
::
base
::
Allocation
::
Free
(
count_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
this
->
template
Get
<
0
>
().
SetListener
(
this
);
...
...
@@ -122,9 +127,14 @@ class Inputs<T1, T2, embb::base::internal::Nil,
embb
::
base
::
internal
::
Nil
,
embb
::
base
::
internal
::
Nil
>
,
public
ClockListener
{
public
:
Inputs
()
{
Inputs
()
:
count_
(
NULL
)
{
test_count_
=
2
;
}
~
Inputs
()
{
if
(
NULL
!=
count_
)
{
embb
::
base
::
Allocation
::
Free
(
count_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
this
->
template
Get
<
0
>
().
SetListener
(
this
);
...
...
@@ -181,9 +191,14 @@ class Inputs<T1, T2, T3, embb::base::internal::Nil,
embb
::
base
::
internal
::
Nil
,
embb
::
base
::
internal
::
Nil
>
,
public
ClockListener
{
public
:
Inputs
()
{
Inputs
()
:
count_
(
NULL
)
{
test_count_
=
3
;
}
~
Inputs
()
{
if
(
NULL
!=
count_
)
{
embb
::
base
::
Allocation
::
Free
(
count_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
this
->
template
Get
<
0
>
().
SetListener
(
this
);
...
...
@@ -243,9 +258,14 @@ class Inputs<T1, T2, T3, T4, embb::base::internal::Nil>
In
<
T4
>
,
embb
::
base
::
internal
::
Nil
>
,
public
ClockListener
{
public
:
Inputs
()
{
Inputs
()
:
count_
(
NULL
)
{
test_count_
=
4
;
}
~
Inputs
()
{
if
(
NULL
!=
count_
)
{
embb
::
base
::
Allocation
::
Free
(
count_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
this
->
template
Get
<
0
>
().
SetListener
(
this
);
...
...
@@ -310,9 +330,14 @@ class Inputs
In
<
T4
>
,
In
<
T5
>
>
,
public
ClockListener
{
public
:
Inputs
()
{
Inputs
()
:
count_
(
NULL
)
{
test_count_
=
5
;
}
~
Inputs
()
{
if
(
NULL
!=
count_
)
{
embb
::
base
::
Allocation
::
Free
(
count_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
this
->
template
Get
<
0
>
().
SetListener
(
this
);
...
...
This diff is collapsed.
Click to expand it.
dataflow_cpp/include/embb/dataflow/internal/process.h
View file @
0e87c034
...
...
@@ -55,6 +55,7 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
explicit
Process
(
FunctionType
function
)
:
executor_
(
function
)
,
action_
(
NULL
)
,
slices_
(
0
)
{
next_clock_
=
0
;
queued_clock_
=
0
;
...
...
@@ -67,6 +68,12 @@ class Process< Serial, Inputs<I1, I2, I3, I4, I5>,
inputs_
.
SetListener
(
this
);
}
~
Process
()
{
if
(
NULL
!=
action_
)
{
embb
::
base
::
Allocation
::
Free
(
action_
);
}
}
virtual
bool
HasInputs
()
const
{
return
inputs_
.
Size
()
>
0
;
}
...
...
This diff is collapsed.
Click to expand it.
dataflow_cpp/include/embb/dataflow/internal/sink.h
View file @
0e87c034
...
...
@@ -49,13 +49,20 @@ class Sink< Inputs<I1, I2, I3, I4, I5> >
typedef
typename
ExecutorType
::
FunctionType
FunctionType
;
explicit
Sink
(
FunctionType
function
)
:
executor_
(
function
)
{
:
executor_
(
function
)
,
action_
(
NULL
)
{
next_clock_
=
0
;
queued_clock_
=
0
;
queue_id_
=
GetNextProcessID
();
inputs_
.
SetListener
(
this
);
}
~
Sink
()
{
if
(
NULL
!=
action_
)
{
embb
::
base
::
Allocation
::
Free
(
action_
);
}
}
void
SetListener
(
ClockListener
*
listener
)
{
listener_
=
listener
;
}
...
...
This diff is collapsed.
Click to expand it.
dataflow_cpp/include/embb/dataflow/network.h
View file @
0e87c034
...
...
@@ -52,10 +52,8 @@ namespace dataflow {
/**
* Represents a set of processes, that are connected by communication channels.
*
* \tparam Slices Number of concurrently processed tokens.
* \ingroup CPP_DATAFLOW
*/
template
<
int
Slices
>
class
Network
{
public
:
/**
...
...
@@ -662,6 +660,14 @@ class Network {
void
AddSource
(
ConstantSource
<
Type
>
&
source
);
/**
* Builds the network for usage with \c slices concurrent tokens. This
* function needs to be called after adding all sources and before
* executing the network.
* \param slices Number of concurrent tokens allowed in the network.
*/
void
Make
(
int
slices
);
/**
* Executes the network until one of the the sources returns \c false.
*/
void
operator
()
();
...
...
@@ -671,7 +677,14 @@ class Network {
class
Network
:
public
internal
::
ClockListener
{
public
:
Network
()
{}
Network
()
:
sched_
(
NULL
)
{}
~
Network
()
{
if
(
NULL
!=
sched_
)
{
embb
::
base
::
Allocation
::
Delete
<
internal
::
Scheduler
>
(
sched_
);
embb
::
base
::
Allocation
::
Free
(
sink_counter_
);
}
}
template
<
typename
T1
,
typename
T2
=
embb
::
base
::
internal
::
Nil
,
typename
T3
=
embb
::
base
::
internal
::
Nil
,
...
...
@@ -799,16 +812,13 @@ class Network : public internal::ClockListener {
sources_
.
push_back
(
&
source
);
}
void
operator
()
(
int
slices
)
{
void
Make
(
int
slices
)
{
slices_
=
slices
;
internal
::
SchedulerSequential
sched_seq
;
internal
::
SchedulerMTAPI
sched_mtapi
(
slices_
);
internal
::
Scheduler
*
sched
=
&
sched_mtapi
;
sched_
=
embb
::
base
::
Allocation
::
New
<
internal
::
SchedulerMTAPI
>
(
slices_
);
internal
::
InitData
init_data
;
init_data
.
slices
=
slices_
;
init_data
.
sched
=
sched
;
init_data
.
sched
=
sched
_
;
init_data
.
sink_listener
=
this
;
sink_counter_
=
reinterpret_cast
<
embb
::
base
::
Atomic
<
int
>*>
(
...
...
@@ -825,12 +835,18 @@ class Network : public internal::ClockListener {
for
(
int
ii
=
0
;
ii
<
slices_
;
ii
++
)
{
sink_counter_
[
ii
]
=
0
;
}
}
void
operator
()
()
{
if
(
NULL
==
sched_
)
{
throw
embb
::
base
::
ErrorException
(
"Network was not properly prepared"
);
}
int
clock
=
0
;
while
(
clock
>=
0
)
{
const
int
idx
=
clock
%
slices_
;
while
(
sink_counter_
[
idx
]
>
0
)
embb
::
base
::
Thread
::
CurrentYield
();
sched
->
WaitForSlice
(
idx
);
sched
_
->
WaitForSlice
(
idx
);
if
(
!
SpawnClock
(
clock
))
break
;
clock
++
;
...
...
@@ -841,7 +857,7 @@ class Network : public internal::ClockListener {
for
(;
ii
<
clock
;
ii
++
)
{
const
int
idx
=
ii
%
slices_
;
while
(
sink_counter_
[
idx
]
>
0
)
embb
::
base
::
Thread
::
CurrentYield
();
sched
->
WaitForSlice
(
idx
);
sched
_
->
WaitForSlice
(
idx
);
}
}
...
...
@@ -875,6 +891,7 @@ class Network : public internal::ClockListener {
embb
::
base
::
Atomic
<
int
>
*
sink_counter_
;
int
sink_count_
;
int
slices_
;
internal
::
Scheduler
*
sched_
;
#if EMBB_DATAFLOW_TRACE_SIGNAL_HISTORY
std
::
vector
<
int
>
spawn_history_
[
Slices
];
...
...
This diff is collapsed.
Click to expand it.
dataflow_cpp/test/dataflow_cpp_test_simple.cc
View file @
0e87c034
...
...
@@ -211,8 +211,10 @@ void SimpleTest::TestBasic() {
network
.
AddSource
(
constant
);
network
.
AddSource
(
source
);
network
.
Make
(
NUM_SLICES
);
try
{
network
(
NUM_SLICES
);
network
();
}
catch
(
embb
::
base
::
ErrorException
&
e
)
{
PT_ASSERT_MSG
(
false
,
e
.
What
());
}
...
...
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