23 #include "ocilibcpp/core.hpp"
24 #include "ocilibcpp/detail/support/HandleStoreResolver.hpp"
25 #include "ocilibcpp/detail/support/HandleDeleter.hpp"
33 HandleHolder<T>::SmartHandle::SmartHandle
35 HandleHolder* holder, T handle,
bool allocated,
36 SmartHandleFreeNotifyFunc freeNotifyFunc, Handle* parent
38 : _holders(), _handle(handle), _allocated(allocated),
39 _freeNotifyFunc(freeNotifyFunc), _parent(parent), _extraInfo(nullptr), _store{nullptr},
40 _guard(GetSynchronizationMode())
42 _holders.SetGuard(&_guard);
43 _children.SetGuard(&_guard);
45 if (support::HandleStoreResolver<T>::RequireStore)
47 _store = core::OnAllocate(
new core::HandleStore(&_guard));
50 HandleStore::GetStoreForHandle(parent).Set<SmartHandle*>(handle,
this);
54 if (_parent && _handle)
56 _parent->GetChildren().Add(
this);
61 HandleHolder<T>::SmartHandle::~SmartHandle() noexcept
63 SILENT_CATCH((Destroy()))
67 void HandleHolder<T>::SmartHandle::Destroy()
69 if (_parent && _handle)
71 _parent->GetChildren().Remove(
this);
74 _children.ForEach(DeleteHandle);
77 _holders.SetGuard(
nullptr);
78 _children.SetGuard(
nullptr);
80 HandleStore::GetStoreForHandle(_parent).Set<SmartHandle*>(_handle,
nullptr);
84 _freeNotifyFunc(
this);
87 if (_handle && _allocated)
89 support::HandleDeleter<T> deleter;
95 delete core::OnDeallocate(_store);
100 void HandleHolder<T>::SmartHandle::DeleteHandle(Handle* handle)
104 handle->DetachFromParent();
105 handle->DetachFromHolders();
107 delete core::OnDeallocate(handle);
112 void HandleHolder<T>::SmartHandle::ResetHolder(HandleHolder* holder)
116 holder->_smartHandle =
nullptr;
123 if ((Environment::GetMode() & Environment::Threaded) == Environment::Threaded)
125 return support::HandleStoreResolver<T>::SynchMode;
128 return SynchronizationMode::Unsafe;
132 void HandleHolder<T>::SmartHandle::Acquire(HandleHolder* holder)
134 _holders.Add(holder);
138 void HandleHolder<T>::SmartHandle::Release(HandleHolder* holder)
140 _holders.Remove(holder);
142 if (_holders.GetSize() == 0)
144 delete core::OnDeallocate(
this);
147 holder->_smartHandle =
nullptr;
151 T HandleHolder<T>::SmartHandle::GetHandle()
const
157 Handle* HandleHolder<T>::SmartHandle::GetParent()
const
163 AnyPointer HandleHolder<T>::SmartHandle::GetExtraInfos()
const
169 void HandleHolder<T>::SmartHandle::SetExtraInfos(AnyPointer extraInfo)
171 _extraInfo = extraInfo;
175 ConcurrentList<Handle*>& HandleHolder<T>::SmartHandle::GetChildren()
181 void HandleHolder<T>::SmartHandle::DetachFromHolders()
183 _holders.ForEach(ResetHolder);
188 void HandleHolder<T>::SmartHandle::DetachFromParent()
194 HandleStore* HandleHolder<T>::SmartHandle::GetStore()
SynchronizationMode
Internal usage. Synchronization mode enumeration.
void * AnyPointer
Alias for the generic void pointer.