vtk-m/vtkm/exec/AtomicArrayExecutionObject.h

66 lines
1.8 KiB
C
Raw Normal View History

2016-02-10 15:51:31 +00:00
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
2016-02-10 15:51:31 +00:00
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_exec_AtomicArrayExecutionObject_h
#define vtk_m_exec_AtomicArrayExecutionObject_h
2016-02-10 15:51:31 +00:00
#include <vtkm/ListTag.h>
2016-02-10 15:51:31 +00:00
#include <vtkm/cont/ArrayHandle.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/cont/DeviceAdapter.h>
2016-02-10 15:51:31 +00:00
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace exec
{
2016-02-10 15:51:31 +00:00
template <typename T, typename Device>
class AtomicArrayExecutionObject
2016-02-10 15:51:31 +00:00
{
public:
using ValueType = T;
VTKM_CONT
AtomicArrayExecutionObject()
: AtomicImplementation((vtkm::cont::ArrayHandle<T>()))
2017-05-18 14:29:41 +00:00
{
}
2017-05-18 14:29:41 +00:00
template <typename StorageType>
VTKM_CONT AtomicArrayExecutionObject(vtkm::cont::ArrayHandle<T, StorageType> handle)
2017-05-18 14:29:41 +00:00
: AtomicImplementation(handle)
2016-02-10 15:51:31 +00:00
{
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
2016-02-10 15:51:31 +00:00
T Add(vtkm::Id index, const T& value) const
{
2017-05-18 14:29:41 +00:00
return this->AtomicImplementation.Add(index, value);
2016-02-10 15:51:31 +00:00
}
2016-03-08 17:58:20 +00:00
//
// Compare and Swap is an atomic exchange operation. If the value at
2016-03-08 17:58:20 +00:00
// the index is equal to oldValue, then newValue is written to the index.
// The operation was successful if return value is equal to oldValue
2016-03-08 17:58:20 +00:00
//
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC
T CompareAndSwap(vtkm::Id index, const T& newValue, const T& oldValue) const
{
2017-05-18 14:29:41 +00:00
return this->AtomicImplementation.CompareAndSwap(index, newValue, oldValue);
}
2016-02-10 15:51:31 +00:00
private:
vtkm::cont::DeviceAdapterAtomicArrayImplementation<T, Device> AtomicImplementation;
};
2016-02-10 15:51:31 +00:00
}
} // namespace vtkm::exec
#endif //vtk_m_exec_AtomicArrayExecutionObject_h