Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Guilhem Saurel
dynamic-graph
Commits
18460a5a
Commit
18460a5a
authored
Sep 23, 2020
by
Julian Viereck
Browse files
Tracer: Adding lock to make it threadsafe
parent
3f6d48d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/tracer.h
View file @
18460a5a
...
...
@@ -8,6 +8,7 @@
#include
<boost/function.hpp>
#include
<list>
#include
<string>
#include
<mutex>
#include
<dynamic-graph/entity.h>
#include
<dynamic-graph/exception-traces.h>
...
...
@@ -27,6 +28,7 @@ class DG_TRACER_DLLAPI Tracer : public Entity {
protected:
typedef
std
::
list
<
const
SignalBase
<
int
>
*>
SignalList
;
SignalList
toTraceSignals
;
std
::
mutex
files_mtx
;
public:
enum
TraceStyle
{
...
...
src/traces/tracer-real-time.cpp
View file @
18460a5a
...
...
@@ -146,6 +146,7 @@ void TracerRealTime::openFile(const SignalBase<int> &sig,
void
TracerRealTime
::
closeFiles
()
{
dgDEBUGIN
(
15
);
std
::
lock_guard
<
std
::
mutex
>
files_lock
(
files_mtx
);
FileList
::
iterator
iter
=
files
.
begin
();
HardFileList
::
iterator
hardIter
=
hardFiles
.
begin
();
...
...
src/traces/tracer.cpp
View file @
18460a5a
...
...
@@ -171,6 +171,7 @@ void Tracer::openFile(const SignalBase<int> &sig, const string &givenname) {
void
Tracer
::
closeFiles
()
{
dgDEBUGIN
(
15
);
std
::
lock_guard
<
std
::
mutex
>
files_lock
(
files_mtx
);
for
(
FileList
::
iterator
iter
=
files
.
begin
();
files
.
end
()
!=
iter
;
++
iter
)
{
std
::
ostream
*
filePtr
=
*
iter
;
...
...
@@ -193,6 +194,14 @@ void Tracer::record() {
dgDEBUGIN
(
15
);
// Ensure record() never hangs. If the attempt to acquire the lock fails,
// then closeFiles() is active and we shouldn't write to files anyways.
std
::
unique_lock
<
std
::
mutex
>
files_lock
(
files_mtx
,
std
::
try_to_lock
);
if
(
!
files_lock
.
owns_lock
())
{
dgDEBUGOUT
(
15
);
return
;
}
if
(
files
.
size
()
!=
toTraceSignals
.
size
())
{
DG_THROW
ExceptionTraces
(
ExceptionTraces
::
NOT_OPEN
,
"No files open for tracing"
,
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment