diff options
author | Anthony Barbier <anthony.barbier@arm.com> | 2018-06-28 13:39:35 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:53:34 +0000 |
commit | d89940e160bc957d37f93f2bdcf5e11ece4d1906 (patch) | |
tree | 471e5815f0c4d63aae7ec34461e189f28b031bcb | |
parent | 19ea419e7f14d02aeb208c2fbd5a4ac55f4cb101 (diff) | |
download | ComputeLibrary-d89940e160bc957d37f93f2bdcf5e11ece4d1906.tar.gz |
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 <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
-rw-r--r-- | src/runtime/CPP/CPPScheduler.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
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 <atomic> #include <condition_variable> #include <iostream> #include <mutex> @@ -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<std::mutex> 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. |