From: Arnaud Giersch Date: Wed, 30 Aug 2017 15:27:50 +0000 (+0200) Subject: Use std::atomic::fetch_add instead of ++ shortcut (clearer to the reader). X-Git-Tag: v3_17~178 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/326d152a10a4c9907e5e54f104f253155abdc851?ds=sidebyside Use std::atomic::fetch_add instead of ++ shortcut (clearer to the reader). --- diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index bc65ff9274..00f4b8c94b 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -224,7 +224,7 @@ template void Parmap::apply(void (*fun)(T), const std::vector */ template boost::optional Parmap::next() { - unsigned index = this->index++; + unsigned index = this->index.fetch_add(1, std::memory_order_relaxed); if (index < this->data->size()) return (*this->data)[index]; else @@ -236,11 +236,11 @@ template boost::optional Parmap::next() */ template void Parmap::work() { - unsigned index = this->index++; unsigned length = this->data->size(); + unsigned index = this->index.fetch_add(1, std::memory_order_relaxed); while (index < length) { this->fun((*this->data)[index]); - index = this->index++; + index = this->index.fetch_add(1, std::memory_order_relaxed); } }