15 template<
class data_t,
class synchronization_primitive_t>
16 inline shared_proxy<data_t, synchronization_primitive_t>::shared_proxy(
18 synchronization_primitive_t* pSynchronizationPrimitive,
20 : m_pSynchronizationPrimitive(pSynchronizationPrimitive)
25 lock_synchronization_primitive(m_pSynchronizationPrimitive);
29 if (!try_lock_synchronization_primitive(m_pSynchronizationPrimitive))
31 m_pSynchronizationPrimitive =
nullptr;
37 template<
class data_t,
class synchronization_primitive_t>
38 inline shared_proxy<data_t, synchronization_primitive_t>::shared_proxy(shared_proxy&& other) noexcept
40 std::swap(m_pSynchronizationPrimitive, other.m_pSynchronizationPrimitive);
41 std::swap(m_pData, other.m_pData);
44 template<
class data_t,
class synchronization_primitive_t>
45 inline shared_proxy<data_t, synchronization_primitive_t>& shared_proxy<data_t, synchronization_primitive_t>::operator=(
46 shared_proxy&& other) noexcept
48 std::swap(m_pSynchronizationPrimitive, other.m_pSynchronizationPrimitive);
49 std::swap(m_pData, other.m_pData);
53 template<
class data_t,
class synchronization_primitive_t>
54 inline shared_proxy<data_t, synchronization_primitive_t>::~shared_proxy()
56 if (m_pSynchronizationPrimitive && m_pData)
57 unlock_synchronization_primitive(m_pSynchronizationPrimitive);
60 template<
class data_t,
class synchronization_primitive_t>
61 inline data_t* shared_proxy<data_t, synchronization_primitive_t>::operator->(
void) noexcept
66 template<
class data_t,
class synchronization_primitive_t>
67 inline const data_t* shared_proxy<data_t, synchronization_primitive_t>::operator->(
void)
const noexcept
72 template<
class data_t,
class synchronization_primitive_t>
73 inline data_t& shared_proxy<data_t, synchronization_primitive_t>::operator*(
void) noexcept
78 template<
class data_t,
class synchronization_primitive_t>
79 inline const data_t& shared_proxy<data_t, synchronization_primitive_t>::operator*(
void)
const noexcept
88 template<
class data_t,
class synchronization_primitive_t>
89 inline threads_shared<data_t, synchronization_primitive_t>::synchronization_primitive_raii::
90 synchronization_primitive_raii()
92 lock_synchronization_primitive(&sp);
95 template<
class data_t,
class synchronization_primitive_t>
96 inline threads_shared<data_t, synchronization_primitive_t>::synchronization_primitive_raii::
97 ~synchronization_primitive_raii()
99 unlock_synchronization_primitive(&sp);
102 template<
class data_t,
class synchronization_primitive_t>
103 inline synchronization_primitive_t* threads_shared<data_t, synchronization_primitive_t>::
104 synchronization_primitive_raii::get_object() noexcept
113 template<
class data_t,
class synchronization_primitive_t>
114 template<
class... args_t>
116 : m_Data(std::forward<args_t>(args)...)
120 unlock_synchronization_primitive(m_SynchronizationPrimitiveRAII.get_object());
123 template<
class data_t,
class synchronization_primitive_t>
129 lock_synchronization_primitive(m_SynchronizationPrimitiveRAII.get_object());
132 template<
class data_t,
class synchronization_primitive_t>
135 synchronization_primitive_t>::lock()
137 return proxy(&m_Data, m_SynchronizationPrimitiveRAII.get_object(),
false);
140 template<
class data_t,
class synchronization_primitive_t>
141 inline std::optional<typename threads_shared<data_t, synchronization_primitive_t>::proxy>
threads_shared<
143 synchronization_primitive_t>::try_lock()
145 auto object =
proxy(&m_Data, m_SynchronizationPrimitiveRAII.get_object(),
true);
146 if (
object.m_pSynchronizationPrimitive &&
object.m_pData)
147 return { std::move(
object) };
A proxy class that provides access to an object stored in threads_shared and provides raii for synchr...
A class that provides thread-safe access to an object, including construction and destruction.
~threads_shared()
threads_shared object destructor