CARLA
 
载入中...
搜索中...
未找到
AtomicSharedPtr.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <memory>
10
11namespace carla {
12
13 /// A very simple atomic shared ptr with release-acquire memory order.
14 template <typename T>
16 public:
17
18 template <typename... Args>
19 explicit AtomicSharedPtr(Args &&... args)
20 : _ptr(std::forward<Args>(args)...) {}
21
23 : _ptr(rhs.load()) {}
24
26
27 void store(std::shared_ptr<T> ptr) noexcept {
28 std::atomic_store_explicit(&_ptr, ptr, std::memory_order_release);
29 }
30
31 void reset(std::shared_ptr<T> ptr = nullptr) noexcept {
32 store(ptr);
33 }
34
35 std::shared_ptr<T> load() const noexcept {
36 return std::atomic_load_explicit(&_ptr, std::memory_order_acquire);
37 }
38
39 bool compare_exchange(std::shared_ptr<T> *expected, std::shared_ptr<T> desired) noexcept {
40 return std::atomic_compare_exchange_strong_explicit(
41 &_ptr,
42 expected,
43 desired,
44 std::memory_order_acq_rel,
45 std::memory_order_acq_rel);
46 }
47
48 AtomicSharedPtr &operator=(std::shared_ptr<T> ptr) noexcept {
49 store(std::move(ptr));
50 return *this;
51 }
52
54 store(rhs.load());
55 return *this;
56 }
57
59
60 private:
61
62 std::shared_ptr<T> _ptr;
63 };
64
65} // namespace carla
A very simple atomic shared ptr with release-acquire memory order.
AtomicSharedPtr(const AtomicSharedPtr &rhs)
AtomicSharedPtr & operator=(std::shared_ptr< T > ptr) noexcept
std::shared_ptr< T > _ptr
AtomicSharedPtr(AtomicSharedPtr &&)=delete
void store(std::shared_ptr< T > ptr) noexcept
AtomicSharedPtr & operator=(AtomicSharedPtr &&)=delete
std::shared_ptr< T > load() const noexcept
AtomicSharedPtr & operator=(const AtomicSharedPtr &rhs) noexcept
bool compare_exchange(std::shared_ptr< T > *expected, std::shared_ptr< T > desired) noexcept
void reset(std::shared_ptr< T > ptr=nullptr) noexcept
AtomicSharedPtr(Args &&... args)
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133