From 5440f89215920b2f985cd120f5404e89efb6b8a2 Mon Sep 17 00:00:00 2001 From: Jeremie Deray <jeremie.deray@pal-robotics.com> Date: Sat, 15 Oct 2016 14:18:20 +0200 Subject: [PATCH] NodeBase & CaptureBase *id_count atomic_uint --- src/capture_base.cpp | 2 +- src/capture_base.h | 2 +- src/node_base.cpp | 2 +- src/node_base.h | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/capture_base.cpp b/src/capture_base.cpp index 2852f011c..e2dd4476e 100644 --- a/src/capture_base.cpp +++ b/src/capture_base.cpp @@ -3,7 +3,7 @@ namespace wolf{ -unsigned int CaptureBase::capture_id_count_ = 0; +std::atomic_uint CaptureBase::capture_id_count_(0); CaptureBase::CaptureBase(const std::string& _type, const TimeStamp& _ts, SensorBasePtr _sensor_ptr) : NodeBase("CAPTURE", _type), diff --git a/src/capture_base.h b/src/capture_base.h index 42447ae2b..4b3046e91 100644 --- a/src/capture_base.h +++ b/src/capture_base.h @@ -23,7 +23,7 @@ class CaptureBase : public NodeBase, public std::enable_shared_from_this<Capture FrameBaseWPtr frame_ptr_; FeatureBaseList feature_list_; - static unsigned int capture_id_count_; + static std::atomic_uint capture_id_count_; protected: unsigned int capture_id_; diff --git a/src/node_base.cpp b/src/node_base.cpp index f6f4ceb53..387b1dc3f 100644 --- a/src/node_base.cpp +++ b/src/node_base.cpp @@ -3,6 +3,6 @@ namespace wolf { //init static node counter -unsigned int NodeBase::node_id_count_ = 0; +std::atomic_uint NodeBase::node_id_count_(0); } // namespace wolf diff --git a/src/node_base.h b/src/node_base.h index c64bbc900..70cfc6569 100644 --- a/src/node_base.h +++ b/src/node_base.h @@ -4,6 +4,8 @@ // Wolf includes #include "wolf.h" +// std includes +#include <atomic> namespace wolf { @@ -54,7 +56,7 @@ namespace wolf { class NodeBase { private: - static unsigned int node_id_count_; ///< Object counter (acts as simple ID factory) + static std::atomic_uint node_id_count_; ///< Object counter (acts as simple ID factory) protected: ProblemWPtr problem_ptr_; -- GitLab