Broom 1.0.0
A thread-local C++ Garbage Collector
Loading...
Searching...
No Matches
atomics.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4
5#include "src/globals.h"
6
7namespace broom {
8// The implementation of all the atomic operations we need through the GC. Any
9// new operations should be added here and their implementation should be
10// abstracted away with our own interfaces. For now, we just use the standard
11// C++ implementation of atomics.
12struct Atomic {
13 template <typename T>
14 requires std::is_integral_v<T>
15 static T RelaxedFetchAdd(T* where, T howmuch) {
16 return std::atomic_fetch_add_explicit(
17 UnsafeCast<volatile std::atomic<T>*>(where), howmuch,
18 std::memory_order_relaxed);
19 }
20 template <typename T>
21 requires std::is_integral_v<T>
22 static T RelaxedFetchSub(T* where, T howmuch) {
23 return std::atomic_fetch_sub_explicit(
24 UnsafeCast<volatile std::atomic<T>*>(where), howmuch,
25 std::memory_order_relaxed);
26 }
27 template <typename T>
28 static void RelaxedStore(T* destination, T what) {
29 std::atomic_store_explicit(
30 UnsafeCast<volatile std::atomic<T>*>(destination), what,
31 std::memory_order_relaxed);
32 }
33 template <typename T>
34 static T RelaxedLoad(T* source) {
35 return std::atomic_load_explicit(
36 UnsafeCast<volatile std::atomic<T>*>(source),
37 std::memory_order_relaxed);
38 }
39};
40} // namespace broom
std::queue< T, broom::deque< T > > queue
Definition broom-queue.h:12
constexpr T UnsafeCast(U v)
Definition globals.h:60
static T RelaxedFetchAdd(T *where, T howmuch)
Definition atomics.h:15
static T RelaxedFetchSub(T *where, T howmuch)
Definition atomics.h:22
static T RelaxedLoad(T *source)
Definition atomics.h:34
static void RelaxedStore(T *destination, T what)
Definition atomics.h:28