scc 2025.09
SystemC components library
tlm_gp_shared.h
1/*******************************************************************************
2 * Copyright 2021-2022 MINRES Technologies GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16
17#ifndef _SYSC_TLM_TLM_GP_SHARED_H_
18#define _SYSC_TLM_TLM_GP_SHARED_H_
19
20#include <tlm>
21
23namespace tlm {
25namespace scc {
26
27template <typename T> class tlm_payload_shared_ptr {
28 T* ptr{nullptr};
29
30public:
32 tlm_payload_shared_ptr() noexcept = default;
33
35 inline tlm_payload_shared_ptr(T* p) noexcept
36 : ptr(p) {
37 if(ptr && ptr->has_mm())
38 ptr->acquire();
39 }
40
42 : ptr(p.ptr) {
43 if(ptr && ptr->has_mm())
44 ptr->acquire();
45 }
46
48 : ptr(std::move(p.ptr)) {
49 p.ptr = nullptr;
50 }
51
53 if(ptr && ptr->has_mm())
54 ptr->release();
55 }
56
58 if(ptr && ptr->has_mm())
59 ptr->release();
60 ptr = p.ptr;
61 if(ptr && ptr->has_mm())
62 ptr->acquire();
63 return *this;
64 }
65
67 if(ptr && ptr->has_mm())
68 ptr->release();
69 ptr = p.ptr;
70 p.ptr = nullptr;
71 return *this;
72 }
73
76 if(ptr && ptr->has_mm())
77 ptr->release();
78 ptr = p;
79 if(ptr && ptr->has_mm())
80 ptr->acquire();
81 return *this;
82 }
83
85 inline T& operator*() const noexcept { return *ptr; }
86
88 inline T* operator->() const noexcept { return ptr; }
89
91 inline T* get() const noexcept { return ptr; }
92
93 inline operator bool() const noexcept { return ptr != nullptr; }
94};
95
96template <typename T> inline std::ostream& operator<<(std::ostream& os, tlm_payload_shared_ptr<T> const& p) {
97 os << p.get();
98 return os;
99}
100
101template <typename T> inline bool operator==(tlm_payload_shared_ptr<T> const& x, tlm_payload_shared_ptr<T> const& y) noexcept {
102 return x.get() == y.get();
103}
104
105template <typename T> inline bool operator==(tlm_payload_shared_ptr<T> const& x, T* y) noexcept { return x.get() == y; }
106
107template <typename T> inline bool operator!=(tlm_payload_shared_ptr<T> const& x, tlm_payload_shared_ptr<T> const& y) noexcept {
108 return x.get() != y.get();
109}
110
112} // namespace scc
113} // namespace tlm
114#endif /* _SYSC_TLM_TLM_GP_SHARED_H_ */
T & operator*() const noexcept
Dereference the stored pointer.
tlm_payload_shared_ptr & operator=(T *p) noexcept
raw pointer assignment operator.
tlm_payload_shared_ptr & operator=(tlm_payload_shared_ptr const &p) noexcept
Copy assignment operator.
tlm_payload_shared_ptr(tlm_payload_shared_ptr const &p) noexcept
Copy constructor.
tlm_payload_shared_ptr() noexcept=default
Default constructor, creates a unique_ptr that owns nothing.
T * operator->() const noexcept
Return the stored pointer.
T * get() const noexcept
Return the stored pointer.
tlm_payload_shared_ptr & operator=(tlm_payload_shared_ptr &&p) noexcept
Move assignment operator.
tlm_payload_shared_ptr(tlm_payload_shared_ptr &&p) noexcept
Move constructor.ยด
SCC TLM utilities.
Definition axis_tlm.h:56
SystemC TLM.
Definition dmi_mgr.h:19