P4 to Git Change 1082378 by lmoriche@lmoriche_opencl_dev on 2014/09/29 17:08:11

ECR #304775 - Replace amd::Atomic with std::atomic

	Pre-checkin: http://ocltc.amd.com:8111/viewModification.html?modId=40639&personal=true&buildTypeId=&tab=vcsModificationBuilds&show_all_builds=true

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#38 edit
... //depot/stg/opencl/drivers/opencl/runtime/os/os_win32.cpp#40 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#64 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#73 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#108 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#86 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/runtime.cpp#33 edit
... //depot/stg/opencl/drivers/opencl/runtime/thread/monitor.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/thread/semaphore.cpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/thread/semaphore.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/util.hpp#10 edit
This commit is contained in:
foreman
2014-09-29 17:38:55 -04:00
parent ad5a7696d1
commit 90c15d9f06
11 changed files with 78 additions and 158 deletions
+37 -2
View File
@@ -6,10 +6,11 @@
#define MONITOR_HPP_
#include "top.hpp"
#include "atomic.hpp"
#include "thread/atomic.hpp"
#include "thread/semaphore.hpp"
#include "thread/thread.hpp"
#include <atomic>
#include <tuple>
#include <utility>
@@ -22,9 +23,43 @@ namespace amd {
* @{
*/
namespace details {
template <class T, class AllocClass = HeapObject>
struct SimplyLinkedNode : public AllocClass
{
typedef SimplyLinkedNode<T, AllocClass> Node;
protected:
std::atomic<Node*> next_; /*!< \brief The next element. */
T volatile item_;
public:
//! \brief Return the next element in the linked-list.
Node* next() const { return next_; }
//! \brief Return the item.
T item() const { return item_; }
//! \brief Set the next element pointer.
void setNext(Node* next) { next_ = next; }
//! \brief Set the item.
void setItem(T item) { item_ = item; }
//! \brief Swap the next element pointer.
Node* swapNext(Node* next) { return next_.swap(next); }
//! \brief Compare and set the next element pointer.
bool compareAndSetNext(Node* compare, Node* next)
{
return next_.compare_exchange_strong(compare, next);
}
};
} // namespace details
class Monitor : public HeapObject
{
typedef SimplyLinkedNode<Semaphore*,StackObject> LinkedNode;
typedef details::SimplyLinkedNode<Semaphore*,StackObject> LinkedNode;
private:
static const bool kUnlocked = false;
+4 -6
View File
@@ -3,7 +3,6 @@
//
#include "thread/semaphore.hpp"
#include "thread/atomic.hpp"
#include "thread/thread.hpp"
#if defined(_WIN32) || defined(__CYGWIN__)
@@ -16,8 +15,8 @@
namespace amd {
Semaphore::Semaphore()
: state_(0)
{
std::atomic_init(&state_, 0);
#ifdef _WIN32
handle_ = static_cast<void*>(CreateSemaphore(NULL, 0, LONG_MAX, NULL));
assert(handle_ != NULL && "CreateSemaphore failed");
@@ -48,14 +47,13 @@ Semaphore::post()
while (true) {
state = state_;
if (state > 0) {
// Do a load acquire.
MemoryOrder::fence();
if (state == state_) {
if (state == state_.load(std::memory_order_acquire)) {
return;
}
continue;
}
if (state_.compareAndSet(state, state+1)) {
if (state_.compare_exchange_weak(state, state+1,
std::memory_order_acq_rel, std::memory_order_acquire)) {
break;
}
}
+5 -5
View File
@@ -6,9 +6,9 @@
#define SEMAPHORE_HPP_
#include "top.hpp"
#include "thread/atomic.hpp"
#include "utils/util.hpp"
#include <atomic>
#if defined(__linux__)
# include <semaphore.h>
#endif /*linux*/
@@ -29,14 +29,14 @@ class Thread;
class Semaphore : public HeapObject
{
private:
Atomic<int> state_; //!< This semaphore's value.
std::atomic_int state_; //!< This semaphore's value.
#ifdef _WIN32
void* handle_; //!< The semaphore object's handle.
char padding_[64-sizeof(void*)-sizeof(Atomic<int>)];
char padding_[64-sizeof(void*)-sizeof(std::atomic_int)];
#else // !_WIN32
sem_t sem_; //!< The semaphore object's identifier.
char padding_[64-sizeof(sem_t)-sizeof(Atomic<int>)];
char padding_[64-sizeof(sem_t)-sizeof(std::atomic_int)];
#endif /*!_WIN32*/
public:
@@ -52,7 +52,7 @@ public:
//! \brief Reset this semaphore.
void reset()
{
state_.swap(0);
state_.store(0, std::memory_order_release);
}
};