From 732beadbf38f9d707d67e4956ba6d1396d1f277b Mon Sep 17 00:00:00 2001 From: foreman Date: Fri, 26 Sep 2014 19:02:58 -0400 Subject: [PATCH] P4 to Git Change 1081826 by lmoriche@lmoriche_opencl_dev on 2014/09/26 18:40:37 ECR #304775 - Replace amd::Atomic with std::atomic Pre-checkin: http://ocltc.amd.com:8111/viewModification.html?modId=40547&personal=true&buildTypeId=&tab=vcsModificationBuilds&show_all_builds=true Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/utils/concurrent.hpp#5 edit [ROCm/clr commit: 23461971a542055277df88d25752f30904b7bd17] --- .../clr/rocclr/runtime/utils/concurrent.hpp | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/projects/clr/rocclr/runtime/utils/concurrent.hpp b/projects/clr/rocclr/runtime/utils/concurrent.hpp index d78b774709..970e43d6bf 100644 --- a/projects/clr/rocclr/runtime/utils/concurrent.hpp +++ b/projects/clr/rocclr/runtime/utils/concurrent.hpp @@ -6,9 +6,9 @@ #define CONCURRENT_HPP_ #include "top.hpp" -#include "thread/atomic.hpp" #include "os/alloc.hpp" +#include #include //! \addtogroup Utils @@ -69,8 +69,8 @@ class ConcurrentLinkedQueue : public HeapObject typedef details::TaggedPointerHelper TaggedPointerHelper; typedef TaggedPointerHelper* Ptr; - T value_; //!< The value stored in that node. - Atomic next_; //!< Pointer to the next node + T value_; //!< The value stored in that node. + std::atomic next_; //!< Pointer to the next node //! Create a Node::Ptr static inline Ptr ptr(Node* ptr, size_t counter = 0) @@ -80,8 +80,8 @@ class ConcurrentLinkedQueue : public HeapObject }; private: - Atomic head_; //! Pointer to the oldest element. - Atomic tail_; //! Pointer to the most recent element. + std::atomic head_; //! Pointer to the oldest element. + std::atomic tail_; //! Pointer to the most recent element. private: //! \brief Allocate a free node. @@ -152,20 +152,24 @@ ConcurrentLinkedQueue::enqueue(T elem) node->next_ = NULL; while (true) { - typename Node::Ptr tail = tail_; - typename Node::Ptr next = tail->ptr()->next_; - MemoryOrder::lfence(); - if (tail == tail_) { + typename Node::Ptr tail = tail_.load(std::memory_order_acquire); + typename Node::Ptr next = + tail->ptr()->next_.load(std::memory_order_acquire); + if (tail == tail_.load(std::memory_order_acquire)) { if (next->ptr() == NULL) { - if (tail->ptr()->next_.compareAndSet( - next, Node::ptr(node, next->tag()+1))) { - tail_.compareAndSet(tail, Node::ptr(node, tail->tag()+1)); + if (tail->ptr()->next_.compare_exchange_weak( + next, Node::ptr(node, next->tag()+1), + std::memory_order_acq_rel, std::memory_order_acquire)) { + tail_.compare_exchange_strong( + tail, Node::ptr(node, tail->tag()+1), + std::memory_order_acq_rel, std::memory_order_acquire); return; } } else { - tail_.compareAndSet( - tail, Node::ptr(next->ptr(), tail->tag()+1)); + tail_.compare_exchange_strong( + tail, Node::ptr(next->ptr(), tail->tag()+1), + std::memory_order_acq_rel, std::memory_order_acquire); } } } @@ -176,22 +180,24 @@ inline T ConcurrentLinkedQueue::dequeue() { while (true) { - typename Node::Ptr head = head_; - typename Node::Ptr tail = tail_; - typename Node::Ptr next = head->ptr()->next_; - MemoryOrder::lfence(); - if (head == head_) { + typename Node::Ptr head = head_.load(std::memory_order_acquire); + typename Node::Ptr tail = tail_.load(std::memory_order_acquire); + typename Node::Ptr next = + head->ptr()->next_.load(std::memory_order_acquire); + if (head == head_.load(std::memory_order_acquire)) { if (head->ptr() == tail->ptr()) { if (next->ptr() == NULL) { return NULL; } - tail_.compareAndSet( - tail, Node::ptr(next->ptr(), tail->tag()+1)); + tail_.compare_exchange_strong( + tail, Node::ptr(next->ptr(), tail->tag()+1), + std::memory_order_acq_rel, std::memory_order_acquire); } else { T value = next->ptr()->value_; - if (head_.compareAndSet( - head, Node::ptr(next->ptr(), head->tag()+1))) { + if (head_.compare_exchange_weak( + head, Node::ptr(next->ptr(), head->tag()+1), + std::memory_order_acq_rel, std::memory_order_acquire)) { // we can reclaim head now reclaimNode(head->ptr()); return value;