From 550b72916a66256091445120489eff7d36f72c2d Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Thu, 9 Feb 2017 17:24:09 -0600 Subject: [PATCH] CkLoop Bug #1364: Replace misused volatile for an atomic counter with portable increment Change-Id: Iea8396a7be71a39a5333782080c06f446a6cfb72 --- src/libs/ck-libs/ckloop/CkLoop.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/libs/ck-libs/ckloop/CkLoop.h b/src/libs/ck-libs/ckloop/CkLoop.h index 80ab125ea6..2acc28eabf 100644 --- a/src/libs/ck-libs/ckloop/CkLoop.h +++ b/src/libs/ck-libs/ckloop/CkLoop.h @@ -27,7 +27,7 @@ class CurLoopInfo { friend class FuncSingleHelper; private: - volatile int curChunkIdx; + int curChunkIdx; // Should become std::atomic int numChunks; HelperFn fnPtr; int lowerIndex; @@ -89,21 +89,9 @@ public: CmiUnlock(loop_info_inited_lock); } int getNextChunkIdx() { -#if defined(_WIN32) -#if CMK_SMP int next_chunk_id; - CmiLock(cmiMemoryLock); - curChunkIdx=curChunkIdx+1; - next_chunk_id = curChunkIdx; - CmiUnlock(cmiMemoryLock); - return next_chunk_id; -#else - curChunkIdx++; - return curChunkIdx; -#endif -#else - return __sync_add_and_fetch(&curChunkIdx, 1); -#endif + CmiMemoryAtomicFetchAndInc(curChunkIdx, next_chunk_id); + return next_chunk_id+1; } void reportFinished(int counter) { if (counter==0) return; -- 2.11.4.GIT