From d89940e160bc957d37f93f2bdcf5e11ece4d1906 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Thu, 28 Jun 2018 13:39:35 +0100 Subject: COMPMID-1345: Switched from using mutexes to atomics in the CPP Scheduler Change-Id: Ie74bb71057027bca3b8a9b03b4a9f156d58b3253 Note: No performance impact as this part of the code is not currently used Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/137807 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- src/runtime/CPP/CPPScheduler.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/runtime/CPP') diff --git a/src/runtime/CPP/CPPScheduler.cpp b/src/runtime/CPP/CPPScheduler.cpp index 0da9892cb2..de28b4f96e 100644 --- a/src/runtime/CPP/CPPScheduler.cpp +++ b/src/runtime/CPP/CPPScheduler.cpp @@ -29,6 +29,7 @@ #include "arm_compute/core/Utils.h" #include "arm_compute/runtime/CPUUtils.h" +#include #include #include #include @@ -48,7 +49,7 @@ public: * @param[in] end End condition (The last value returned by get_next() will be end - 1) */ explicit ThreadFeeder(unsigned int start = 0, unsigned int end = 0) - : _current(start), _end(end), _m() + : _atomic_counter(start), _end(end) { } /** Return the next element in the range if there is one. @@ -59,20 +60,13 @@ public: */ bool get_next(unsigned int &next) { - std::lock_guard lock(_m); - if(_current < _end) - { - next = _current; - _current++; - return true; - } - return false; + next = atomic_fetch_add_explicit(&_atomic_counter, 1u, std::memory_order_relaxed); + return next < _end; } private: - unsigned int _current; + std::atomic_uint _atomic_counter; const unsigned int _end; - std::mutex _m; }; /** Execute workloads[info.thread_id] first, then call the feeder to get the index of the next workload to run. -- cgit v1.2.1