Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
atomics.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// atomics for Realm - this is a simple wrapper around C++11's std::atomic
19// if available and uses gcc's __sync_* primitives otherwise
20
21#ifndef REALM_ATOMICS_H
22#define REALM_ATOMICS_H
23
24#include "realm/realm_config.h"
25
26#include <atomic>
27
28namespace Realm {
29
30 template <typename T>
31 class atomic {
32 public:
33 atomic(void);
34
35 // this is explicit to disallow assignment of base value (must use store())
36 explicit atomic(T _value);
37
38 // copy constructors are needed if atomics are put in a container
39 atomic(const atomic<T> &copy_from);
40 atomic<T> &operator=(const atomic<T> &copy_from);
41
42 T load(void) const;
43 T load_acquire(void) const;
44 // a fenced load is an load_acquire that cannot be reordered with earlier stores
45 T load_fenced(void) const;
46
47 void store(T newval);
48 void store_release(T newval);
49
50 // atomic ops
51 T exchange(T newval);
52 bool compare_exchange(T &expected, T newval);
53 bool compare_exchange_relaxed(T &expected, T newval);
54 bool compare_exchange_weak(T &expected, T newval);
55
56 // these updates use relaxed semantics, guaranteeing atomicity, but
57 // imposing no constraints on other loads and stores - use *_acqrel
58 // variants below for fencing behavior
59 T fetch_add(T to_add);
60 T fetch_sub(T to_sub);
61 T fetch_and(T to_and);
62 T fetch_or(T to_or);
63 T fetch_xor(T to_xor);
64 T fetch_min(T to_min);
65 T fetch_max(T to_max);
66
67 T fetch_add_acqrel(T to_add);
68 T fetch_sub_acqrel(T to_sub);
69 T fetch_and_acqrel(T to_and);
70 T fetch_or_acqrel(T to_or);
71 T fetch_xor_acqrel(T to_xor);
72 T fetch_min_acqrel(T to_min);
73 T fetch_max_acqrel(T to_max);
74
75 protected:
76 std::atomic<T> value;
77 };
78
79}; // namespace Realm
80
81#include "realm/atomics.inl"
82
83#endif
Definition atomics.h:31
T fetch_and(T to_and)
void store_release(T newval)
T load(void) const
std::atomic< T > value
Definition atomics.h:76
T fetch_and_acqrel(T to_and)
T fetch_or_acqrel(T to_or)
T exchange(T newval)
T fetch_xor_acqrel(T to_xor)
T fetch_max_acqrel(T to_max)
T fetch_min_acqrel(T to_min)
T fetch_min(T to_min)
void store(T newval)
bool compare_exchange_weak(T &expected, T newval)
T fetch_max(T to_max)
atomic< T > & operator=(const atomic< T > &copy_from)
T fetch_or(T to_or)
atomic(const atomic< T > &copy_from)
bool compare_exchange_relaxed(T &expected, T newval)
T fetch_sub(T to_sub)
T fetch_add_acqrel(T to_add)
T fetch_add(T to_add)
atomic(T _value)
bool compare_exchange(T &expected, T newval)
T load_fenced(void) const
T fetch_xor(T to_xor)
T load_acquire(void) const
T fetch_sub_acqrel(T to_sub)
Definition activemsg.h:38