-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathall_ptrs.hpp
42 lines (31 loc) · 1.27 KB
/
all_ptrs.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include <memory>
#include <folly/concurrency/AtomicSharedPtr.h>
#include "external/anthonywilliams/atomic_shared_ptr"
#include "external/vtyulb/atomic_shared_ptr.h"
#ifdef JUST_THREADS_AVAILABLE
#include <experimental/atomic>
#endif
#include "parlay/atomic_shared_ptr.hpp"
#include "parlay/basic_atomic_shared_ptr.hpp"
#ifdef __cpp_lib_atomic_shared_ptr
// C++ standard library atomic support for shared ptrs
template<typename T>
using StlAtomicSharedPtr = std::atomic<std::shared_ptr<T>>;
#else
// Use free functions if std::atomic<shared_ptr> is not available. Much worse.
template<typename T>
struct StlAtomicSharedPtr {
StlAtomicSharedPtr() = default;
explicit(false) StlAtomicSharedPtr(std::shared_ptr<T> other) : sp(std::move(other)) { } // NOLINT
std::shared_ptr<T> load() { return std::atomic_load(&sp); }
void store(std::shared_ptr<T> r) { std::atomic_store(&sp, std::move(r)); }
bool compare_exchange_strong(std::shared_ptr<T>& expected, std::shared_ptr<T> desired) {
return atomic_compare_exchange_strong(&sp, &expected, std::move(desired));
}
bool compare_exchange_weak(std::shared_ptr<T>& expected, std::shared_ptr<T> desired) {
return atomic_compare_exchange_weak(&sp, &expected, std::move(desired));
}
std::shared_ptr<T> sp;
};
#endif