Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
db354340
Commit
db354340
authored
8 years ago
by
Jeremie Deray
Browse files
Options
Downloads
Patches
Plain Diff
wip PocessorBase as a ThreadedBaseClass
parent
a5510604
No related branches found
No related tags found
1 merge request
!90
[WIP] ProcessorBase multi-threading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/CMakeLists.txt
+3
-0
3 additions, 0 deletions
src/CMakeLists.txt
src/processor_base.cpp
+3
-1
3 additions, 1 deletion
src/processor_base.cpp
src/processor_base.h
+82
-2
82 additions, 2 deletions
src/processor_base.h
with
88 additions
and
3 deletions
src/CMakeLists.txt
+
3
−
0
View file @
db354340
...
...
@@ -183,6 +183,8 @@ SET(HDRS
state_quaternion.h
time_stamp.h
trajectory_base.h
threaded_base_class.h
multi_threading_utils.h
)
...
...
@@ -247,6 +249,7 @@ SET(SRCS
sensor_odom_3D.cpp
time_stamp.cpp
trajectory_base.cpp
threaded_base_class.cpp
data_association/association_solver.cpp
data_association/association_node.cpp
data_association/association_tree.cpp
...
...
This diff is collapsed.
Click to expand it.
src/processor_base.cpp
+
3
−
1
View file @
db354340
...
...
@@ -6,8 +6,10 @@ namespace wolf {
unsigned
int
ProcessorBase
::
processor_id_count_
=
0
;
ProcessorBase
::
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
)
:
ProcessorBase
::
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
,
const
Scalar
_processing_rate
)
:
NodeBase
(
"PROCESSOR"
),
ThreadedBaseClass
(
_processing_rate
),
sensor_ptr_
(),
processor_id_
(
++
processor_id_count_
),
type_id_
(
_tp
),
...
...
This diff is collapsed.
Click to expand it.
src/processor_base.h
+
82
−
2
View file @
db354340
...
...
@@ -9,6 +9,7 @@ class SensorBase;
//Wolf includes
#include
"wolf.h"
#include
"node_base.h"
#include
"threaded_base_class.h"
// std
#include
<memory>
...
...
@@ -28,12 +29,15 @@ struct ProcessorParamsBase
};
//class ProcessorBase
class
ProcessorBase
:
public
NodeBase
,
public
std
::
enable_shared_from_this
<
ProcessorBase
>
class
ProcessorBase
:
public
NodeBase
,
public
core
::
ThreadedBaseClass
,
public
std
::
enable_shared_from_this
<
ProcessorBase
>
{
private:
SensorBaseWPtr
sensor_ptr_
;
public:
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
=
0
);
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
=
0
,
const
Scalar
_processing_rate
=
2000
);
virtual
~
ProcessorBase
();
void
remove
();
...
...
@@ -41,6 +45,8 @@ class ProcessorBase : public NodeBase, public std::enable_shared_from_this<Proce
virtual
void
process
(
CaptureBasePtr
_capture_ptr
)
=
0
;
virtual
void
addCapture
(
CaptureBasePtr
_capture_ptr
);
/** \brief Vote for KeyFrame generation
*
* If a KeyFrame criterion is validated, this function returns true,
...
...
@@ -74,6 +80,13 @@ class ProcessorBase : public NodeBase, public std::enable_shared_from_this<Proce
unsigned
int
processor_id_
;
ProcessorType
type_id_
;
Scalar
time_tolerance_
;
///< self time tolerance for adding a capture into a frame
std
::
mutex
capture_mut_
;
std
::
atomic
<
bool
>
update_
;
CaptureBasePtr
current_capture_
;
virtual
void
executeImpl
();
};
}
...
...
@@ -81,8 +94,75 @@ class ProcessorBase : public NodeBase, public std::enable_shared_from_this<Proce
#include
"sensor_base.h"
#include
"constraint_base.h"
#include
"multi_threading_utils.h"
namespace
wolf
{
// WOLF_INFO below are their for debugging purpose only
inline
void
ProcessorBase
::
addCapture
(
CaptureBasePtr
_capture_ptr
)
{
// wait to lock the mutex
std
::
unique_lock
<
std
::
mutex
>
lock
(
capture_mut_
);
if
(
!
run_
.
load
(
std
::
memory_order_acquire
))
{
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" asked to stop **************
\n
"
);
return
;
}
// If a copy id needed, it should
// be performed in process(CaptureBasePtr).
current_capture_
=
_capture_ptr
;
lock
.
unlock
();
update_
.
store
(
true
,
std
::
memory_order_release
);
cv_
.
notify_one
();
}
inline
void
ProcessorBase
::
executeImpl
()
{
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl **************"
);
// This basically put the thread asleep until someone
// sets 'update_' or '!run_' from outside
std
::
unique_lock
<
std
::
mutex
>
lock
(
capture_mut_
);
cv_
.
wait
(
lock
,
[
this
]{
return
update_
.
load
(
std
::
memory_order_acquire
)
||
!
run_
.
load
(
std
::
memory_order_acquire
);});
if
(
!
run_
.
load
(
std
::
memory_order_acquire
))
{
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl asked to stop **************"
);
return
;
}
else
if
(
!
update_
.
load
(
std
::
memory_order_acquire
))
{
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl NO update **************"
);
return
;
}
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl actual processing **************
\n
"
,
"
\t\t\t
in thread : "
,
std
::
to_string
(
core
::
get_thread_id
()));
// Process the capture
process
(
current_capture_
);
lock
.
unlock
();
update_
.
store
(
false
,
std
::
memory_order_release
);
cv_
.
notify_one
();
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl End **************"
);
}
inline
wolf
::
ProblemPtr
ProcessorBase
::
getProblem
()
{
ProblemPtr
prb
=
problem_ptr_
.
lock
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment