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
f95badd3
Commit
f95badd3
authored
8 years ago
by
Jeremie Deray
Browse files
Options
Downloads
Patches
Plain Diff
wip ProcessingCapturePolicy & thread priority
parent
c94114c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!90
[WIP] ProcessorBase multi-threading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/multi_threading_utils.h
+10
-0
10 additions, 0 deletions
src/multi_threading_utils.h
src/processor_base.cpp
+7
-2
7 additions, 2 deletions
src/processor_base.cpp
src/processor_base.h
+58
-28
58 additions, 28 deletions
src/processor_base.h
with
75 additions
and
30 deletions
src/multi_threading_utils.h
+
10
−
0
View file @
f95badd3
...
...
@@ -166,6 +166,16 @@ inline void locked_cout(const CoutColor& color, const Args&... rest)
#define WOLF_ERROR_COND(...) \
if (cond) locked_cout(cond, wolf::io::CoutColor::RED, __VA_ARGS__)
// I need to define some custom debugging
// flag (e.g. WOLFDEBUG) that I can pass to
// gcc through cmake.
#if 0
#define WOLF_DEBUG(...)
#else
#define WOLF_DEBUG(...) \
locked_cout(wolf::io::CoutColor::CYAN, __VA_ARGS__)
#endif
}
// namespace wolf
#endif
/* WOLF_MULTI_THREADING_UTILS_H_ */
This diff is collapsed.
Click to expand it.
src/processor_base.cpp
+
7
−
2
View file @
f95badd3
...
...
@@ -7,13 +7,18 @@ namespace wolf {
unsigned
int
ProcessorBase
::
processor_id_count_
=
0
;
ProcessorBase
::
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
,
const
Scalar
_processing_rate
)
:
const
Scalar
&
_time_tolerance
,
const
Scalar
_processing_rate
,
const
ProcessingCapturePolicy
policy
)
:
NodeBase
(
"PROCESSOR"
),
ThreadedBaseClass
(
_processing_rate
),
sensor_ptr_
(),
processor_id_
(
++
processor_id_count_
),
type_id_
(
_tp
),
time_tolerance_
(
_time_tolerance
)
time_tolerance_
(
_time_tolerance
),
proc_capture_policy_
(
policy
),
update_
(
false
),
processed_
(
false
),
capturing_
(
false
)
{
std
::
cout
<<
"constructed +p"
<<
id
()
<<
std
::
endl
;
...
...
This diff is collapsed.
Click to expand it.
src/processor_base.h
+
58
−
28
View file @
f95badd3
...
...
@@ -28,6 +28,12 @@ struct ProcessorParamsBase
std
::
string
name
;
};
enum
class
ProcessingCapturePolicy
{
STRICT
,
SOFT
};
//class ProcessorBase
class
ProcessorBase
:
public
NodeBase
,
public
core
::
ThreadedBaseClass
,
public
std
::
enable_shared_from_this
<
ProcessorBase
>
{
...
...
@@ -36,7 +42,8 @@ class ProcessorBase : public NodeBase, public core::ThreadedBaseClass, public st
public:
ProcessorBase
(
ProcessorType
_tp
,
const
std
::
string
&
_type
,
const
Scalar
&
_time_tolerance
=
0
,
const
Scalar
_processing_rate
=
2000
);
const
Scalar
&
_time_tolerance
=
0
,
const
Scalar
_capturing_rate
=
2000
,
const
ProcessingCapturePolicy
policy
=
ProcessingCapturePolicy
::
STRICT
);
virtual
~
ProcessorBase
();
void
remove
();
...
...
@@ -81,8 +88,13 @@ class ProcessorBase : public NodeBase, public core::ThreadedBaseClass, public st
ProcessorType
type_id_
;
Scalar
time_tolerance_
;
///< self time tolerance for adding a capture into a frame
ProcessingCapturePolicy
proc_capture_policy_
;
std
::
mutex
capture_mut_
;
std
::
atomic
<
bool
>
update_
;
std
::
atomic
<
bool
>
processed_
;
std
::
atomic
<
bool
>
capturing_
;
CaptureBasePtr
current_capture_
;
...
...
@@ -98,34 +110,58 @@ class ProcessorBase : public NodeBase, public core::ThreadedBaseClass, public st
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_
);
WOLF_DEBUG
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" addCapture wait **************"
);
if
(
!
run_
.
load
(
std
::
memory_order_acquire
))
std
::
unique_lock
<
std
::
mutex
>
lock
;
switch
(
proc_capture_policy_
)
{
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" asked to stop **************
\n
"
);
return
;
case
ProcessingCapturePolicy
::
SOFT
:
{
lock
=
std
::
unique_lock
<
std
::
mutex
>
(
capture_mut_
,
std
::
try_to_lock
);
// If try_lock fails, the capture is lost
if
(
!
lock
.
owns_lock
())
return
;
}
case
ProcessingCapturePolicy
::
STRICT
:
{
// wait to lock the mutex
lock
=
std
::
unique_lock
<
std
::
mutex
>
(
capture_mut_
);
cv_
.
wait
(
lock
,
[
this
]{
return
!
capturing_
.
load
(
std
::
memory_order_acquire
)
||
!
run_
.
load
(
std
::
memory_order_acquire
);});
break
;
}
default
:
{
// wait to lock the mutex
lock
=
std
::
unique_lock
<
std
::
mutex
>
(
capture_mut_
);
cv_
.
wait
(
lock
,
[
this
]{
return
!
capturing_
.
load
(
std
::
memory_order_acquire
)
||
!
run_
.
load
(
std
::
memory_order_acquire
);});
break
;
}
}
if
(
!
run_
.
load
(
std
::
memory_order_acquire
))
return
;
capturing_
.
store
(
true
,
std
::
memory_order_release
);
WOLF_DEBUG
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" addCapture do **************"
);
// 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
();
lock
.
unlock
();
}
inline
void
ProcessorBase
::
executeImpl
()
{
WOLF_
INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl **************"
);
WOLF_
DEBUG
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl
wait
**************"
);
// This basically put the thread asleep until someone
// sets 'update_' or '!run_' from outside
...
...
@@ -135,32 +171,26 @@ inline void ProcessorBase::executeImpl()
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 **************"
);
// WOLF_DEBUG("************** ProcessorBase " + std::to_string(id()) +
// " executeImpl asked to stop **************");
return
;
}
WOLF_INFO
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl actual processing **************
\n
"
,
"
\t\t\t
in thread : "
,
std
::
to_string
(
core
::
get_thread_id
()));
WOLF_DEBUG
(
"************** ProcessorBase "
+
std
::
to_string
(
id
())
+
" executeImpl do **************"
);
capturing_
.
store
(
false
,
std
::
memory_order_release
);
// WOLF_DEBUG("************** 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 **************"
);
lock
.
unlock
();
}
inline
wolf
::
ProblemPtr
ProcessorBase
::
getProblem
()
...
...
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