12#ifndef ARCCORE_BASE_REFERENCECOUNTERIMPL_H
13#define ARCCORE_BASE_REFERENCECOUNTERIMPL_H
17#include "arccore/base/ReferenceCounter.h"
18#include "arccore/base/RefBase.h"
40template <
class T> ARCCORE_EXPORT
void
41ExternalReferenceCounterAccessor<T>::
44 if constexpr (impl::HasInternalAddReference<T>::value)
45 t->_internalAddReference();
53template <
class T> ARCCORE_EXPORT
void
54ExternalReferenceCounterAccessor<T>::
57 if constexpr (impl::HasInternalRemoveReference<T>::value) {
58 bool need_destroy = t->_internalRemoveReference();
96 void removeReference()
101 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
103 if (_destroyThisReference())
110 void _internalAddReference()
114 bool _internalRemoveReference()
119 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
121 return _destroyThisReference();
130 delete m_external_deleter;
131 m_external_deleter = v;
135 return m_external_deleter;
140 std::atomic<Int32> m_nb_ref = 0;
146 bool _destroyThisReference()
148 if (!m_external_deleter)
150 bool do_delete =
false;
152 bool is_destroyed = m_external_deleter->_destroyHandle(
this, m_external_deleter->
m_handle);
157 delete m_external_deleter;
158 m_external_deleter =
nullptr;
169#define ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(OPTIONAL_OVERRIDE) \
172 using BaseCounterType = ::Arccore::ReferenceCounterImpl; \
176 BaseCounterType* _internalReferenceCounter() OPTIONAL_OVERRIDE \
180 void _internalAddReference() OPTIONAL_OVERRIDE \
182 BaseCounterType::_internalAddReference(); \
184 bool _internalRemoveReference() OPTIONAL_OVERRIDE \
186 return BaseCounterType::_internalRemoveReference(); \
211#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS() \
212 ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(override)
233#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name) \
234 template class ExternalReferenceCounterAccessor<class_name>
bool m_no_destroy
Indique si on doit appeler le destructeur de l'instance lorsqu'il n'y a plus de références dessus.
Internal::ExternalRef m_handle
Handle externe qui se charge de la destruction de l'instance.
Implémentation thread-safe d'un compteur de référence.
Wrapper autour d'une classe gérant son propre compteur de référence.
Espace de nom de Arccore.
std::int32_t Int32
Type entier signé sur 32 bits.