vecmem 1.14.0
Loading...
Searching...
No Matches
posix_device_atomic_ref.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2022-2024 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// Local include(s).
11#include "vecmem/memory/device_address_space.hpp"
12#include "vecmem/memory/memory_order.hpp"
13#include "vecmem/utils/types.hpp"
14
15// System include(s).
16#include <type_traits>
17
18namespace vecmem {
19
25template <typename T,
26 device_address_space address = device_address_space::global>
28
29public:
32
34 typedef T value_type;
41
43
46
47 static_assert(std::is_integral<value_type>::value,
48 "vecmem::posix_device_atomic_ref only accepts built-in "
49 "integral types");
50
52
54 VECMEM_HOST
57 VECMEM_HOST
59
62
65
70 VECMEM_HOST
72
74 VECMEM_HOST
75 void store(value_type data,
76 memory_order order = memory_order::seq_cst) const;
78 VECMEM_HOST
79 value_type load(memory_order order = memory_order::seq_cst) const;
80
82 VECMEM_HOST
84 memory_order order = memory_order::seq_cst) const;
85
87 VECMEM_HOST
90 memory_order failure) const;
92 VECMEM_HOST
95 memory_order order = memory_order::seq_cst) const;
96
98
101
103 VECMEM_HOST
105 memory_order order = memory_order::seq_cst) const;
107 VECMEM_HOST
109 memory_order order = memory_order::seq_cst) const;
110
112 VECMEM_HOST
114 memory_order order = memory_order::seq_cst) const;
116 VECMEM_HOST
118 memory_order order = memory_order::seq_cst) const;
120 VECMEM_HOST
122 memory_order order = memory_order::seq_cst) const;
123
125
126private:
128 pointer m_ptr;
129
130}; // class posix_device_atomic_ref
131
132} // namespace vecmem
133
134// Include the implementation.
135#include "vecmem/memory/impl/posix_device_atomic_ref.ipp"
Custom implementation for atomic operations using "POSIX" built-ins.
Definition posix_device_atomic_ref.hpp:27
VECMEM_HOST value_type fetch_add(value_type data, memory_order order=memory_order::seq_cst) const
Add a chosen value to the stored variable.
Definition posix_device_atomic_ref.ipp:112
VECMEM_HOST bool compare_exchange_strong(reference expected, value_type desired, memory_order success, memory_order failure) const
Compare against the current value, and exchange only if different.
Definition posix_device_atomic_ref.ipp:98
value_type difference_type
Difference between two objects.
Definition posix_device_atomic_ref.hpp:36
VECMEM_HOST void store(value_type data, memory_order order=memory_order::seq_cst) const
Set the variable to the desired value.
Definition posix_device_atomic_ref.ipp:61
VECMEM_HOST value_type fetch_or(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value OR-d to it.
Definition posix_device_atomic_ref.ipp:136
posix_device_atomic_ref & operator=(const posix_device_atomic_ref &)=delete
Disable the assignment operator.
VECMEM_HOST value_type fetch_and(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value AND-ed to it.
Definition posix_device_atomic_ref.ipp:128
VECMEM_HOST value_type exchange(value_type data, memory_order order=memory_order::seq_cst) const
Exchange the current value of the variable with a different one.
Definition posix_device_atomic_ref.ipp:75
VECMEM_HOST value_type load(memory_order order=memory_order::seq_cst) const
Get the value of the variable.
Definition posix_device_atomic_ref.ipp:68
value_type * pointer
Pointer to the value in global memory.
Definition posix_device_atomic_ref.hpp:38
T value_type
Type managed by the object.
Definition posix_device_atomic_ref.hpp:34
VECMEM_HOST value_type fetch_sub(value_type data, memory_order order=memory_order::seq_cst) const
Substitute a chosen value from the stored variable.
Definition posix_device_atomic_ref.ipp:120
VECMEM_HOST value_type fetch_xor(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value XOR-d to it.
Definition posix_device_atomic_ref.ipp:144
value_type & reference
Reference to a value given by the user.
Definition posix_device_atomic_ref.hpp:40
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
device_address_space
Custom definition for the device memory adress space.
Definition device_address_space.hpp:12
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
memory_order
Custom (dummy) definition for the memory order.
Definition memory_order.hpp:31