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
44 if constexpr (::Arcane::impl::HasInternalAddReference<T>::value)
45 t->_internalAddReference();
53template <
class T> ARCCORE_EXPORT
void
57 if constexpr (::Arcane::impl::HasInternalRemoveReference<T>::value) {
58 bool need_destroy = t->_internalRemoveReference();
107 void removeReference()
112 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
121 void _internalAddReference()
125 bool _internalRemoveReference()
130 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
141 delete m_external_deleter;
142 m_external_deleter = v;
146 return m_external_deleter;
151 std::atomic<Int32> m_nb_ref = 0;
159 if (!m_external_deleter)
161 bool do_delete =
false;
162 if (!m_external_deleter->m_no_destroy) {
163 bool is_destroyed = m_external_deleter->_destroyHandle(
this, m_external_deleter->m_handle);
168 delete m_external_deleter;
169 m_external_deleter =
nullptr;
180#define ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(OPTIONAL_OVERRIDE) \
183 using BaseCounterType = ::Arcane::ReferenceCounterImpl; \
187 BaseCounterType* _internalReferenceCounter() OPTIONAL_OVERRIDE \
191 void _internalAddReference() OPTIONAL_OVERRIDE \
193 BaseCounterType::_internalAddReference(); \
195 bool _internalRemoveReference() OPTIONAL_OVERRIDE \
197 return BaseCounterType::_internalRemoveReference(); \
222#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS() \
223 ARCCORE_INTERNAL_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS(override)
244#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name) \
245 template class ExternalReferenceCounterAccessor<class_name>
Implémentation thread-safe d'un compteur de référence.
bool _destroyThisReference()
Retourne true si l'instance doit être détruite par l'appel à operator delete()
Wrapper autour d'une classe gérant son propre compteur de référence.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int32_t Int32
Type entier signé sur 32 bits.
Espace de nom de Arccore.