vecmem 1.14.0
Loading...
Searching...
No Matches
posix_device_atomic_ref.ipp
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// System include(s).
11#include <cassert>
12
13namespace vecmem {
14namespace details {
15
21 switch (o) {
22 case memory_order::relaxed:
23 return __ATOMIC_RELAXED;
24 case memory_order::consume:
25 return __ATOMIC_CONSUME;
26 case memory_order::acquire:
27 return __ATOMIC_ACQUIRE;
28 case memory_order::release:
29 return __ATOMIC_RELEASE;
30 case memory_order::acq_rel:
31 return __ATOMIC_ACQ_REL;
32 case memory_order::seq_cst:
33 return __ATOMIC_SEQ_CST;
34 default:
35 assert(false);
36 return 0;
37 }
38}
39
40} // namespace details
41
42template <typename T, device_address_space address>
46
47template <typename T, device_address_space address>
49 const posix_device_atomic_ref& parent)
50 : m_ptr(parent.m_ptr) {}
51
52template <typename T, device_address_space address>
54 value_type data) const -> value_type {
55
56 store(data);
57 return data;
58}
59
60template <typename T, device_address_space address>
66
67template <typename T, device_address_space address>
73
74template <typename T, device_address_space address>
81
82template <typename T, device_address_space address>
85
86 if (order == memory_order::acq_rel) {
87 return compare_exchange_strong(expected, desired, order,
88 memory_order::acquire);
89 } else if (order == memory_order::release) {
90 return compare_exchange_strong(expected, desired, order,
91 memory_order::relaxed);
92 } else {
94 }
95}
96
97template <typename T, device_address_space address>
110
111template <typename T, device_address_space address>
118
119template <typename T, device_address_space address>
126
127template <typename T, device_address_space address>
134
135template <typename T, device_address_space address>
142
143template <typename T, device_address_space address>
150
151} // namespace vecmem
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
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 posix_device_atomic_ref(reference ref)
Constructor, with a pointer to the managed variable.
Definition posix_device_atomic_ref.ipp:43
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
VECMEM_HOST bool compare_exchange_strong(reference expected, value_type desired, memory_order order=memory_order::seq_cst) const
Compare against the current value, and exchange only if different.
Definition posix_device_atomic_ref.ipp:83
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
constexpr int memorder_to_posix_builtin(memory_order o)
Convert a memory order to the corresponding builtin memory order.
Definition posix_device_atomic_ref.ipp:20
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
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