69template<
typename T,
typename TAllocator,
typename TLock>
81 std::atomic<unsigned int> refCount;
85 size_t initialBufferSize,
86 unsigned int bufferGrowthInPercent )
87 : allocator( pAllocator, firstBuffer, initialBufferSize, bufferGrowthInPercent )
90 template<
typename TRequires= TAllocator>
91 requires std::default_initializable<TRequires>
93 size_t initialBufferSize,
94 unsigned int bufferGrowthInPercent )
95 : allocator(
ALIB_DBG(
"ShardMonoVal",) firstBuffer, initialBufferSize, bufferGrowthInPercent)
127 size_t initialBufferSize,
128 unsigned int bufferGrowthInPercent )
129 :
allocator( pAllocator, firstBuffer, initialBufferSize, bufferGrowthInPercent )
141 template<
typename TRequires= TAllocator>
142 requires std::default_initializable<TRequires>
144 size_t initialBufferSize,
145 unsigned int bufferGrowthInPercent )
147 firstBuffer, initialBufferSize, bufferGrowthInPercent )
152 #if ALIB_DEBUG && !DOXYGEN
155 void dbgassert()
const {}
163 using FieldMembers= std::conditional_t<std::same_as<void, TLock>, FieldMembersNoLock, FieldMembersWithLock>;
198 size_t initialBufferSizeInKB,
unsigned int bufferGrowthInPercent )
200 auto size= initialBufferSizeInKB * 1024;
207 "Initial buffer size {} to small to hold shared value of size {}.",
227 TSharedMonoVal(
size_t initialBufferSizeInKB,
unsigned int bufferGrowthInPercent )
229 auto size= initialBufferSizeInKB * 1024;
230 void* mem= TAllocator().allocate( size,
alignof(
detail::Buffer) );
235 "Initial buffer size {} to small to hold shared value of size {}.",
246 "Template parameter TLock of class TSharedMonoVal must be <void> if module ALib Threads is "
247 "not included in the ALib Build." )
270 template<
typename... TArgs>
280 new (&
members->custom) T( std::forward<TArgs>(args)... );
295 template<
typename... TArgs>
296 void ConstructT( TArgs&&... args ) {
members->custom.Construct(std::forward<TArgs>(args)... ); }
316 const T&
Self() const noexcept { dbgassert();
return *
members->custom; }
358 :
members(other.members) { other.members=
nullptr; }
369 if (
this == &other || this->members == other.members)
380 if((
members= other.members) !=
nullptr)
405 other.members=
nullptr;
444 T*
Get() noexcept { dbgassert();
return members->custom.Get(); }
448 const T*
Get() const noexcept { dbgassert();
return members->custom.Get(); }
451 operator bool() const noexcept {
return members !=
nullptr; }
613 #elif !ALIB_SINGLE_THREADED
614 #define ATPASS ALIB_STATIC_ASSERT(ForbiddenTemplateParameterGiven, std::same_as<TRq ALIB_COMMA TLock>, "Template parameter of this method is deduced by the compiler and must not be given!");
615 template<
typename TRq= TLock>
requires (!std::same_as<TRq, void> )
616 TRq&
GetLock() const noexcept { ATPASS dbgassert();
return members->lock; }
673DOX_MARKER([DOX_MANUAL_ALIASES_SHAREDMONOVAL])
675template<
typename T,
typename TAllocator= lang::HeapAllocator,
typename TLock=
void>
677DOX_MARKER([DOX_MANUAL_ALIASES_SHAREDMONOVAL])
bool TryAcquireTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci) const noexcept
void ReleaseShared(const CallerInfo &ci) const noexcept
bool Unique() const noexcept
bool IsNulled() const noexcept
const T * Get() const noexcept
void ReleaseRecursive(const CallerInfo &ci) const noexcept
bool TryAcquireShared(const CallerInfo &ci) const noexcept
unsigned int UseCount() const noexcept
void ConstructT(TArgs &&... args)
void AcquireRecursive(const CallerInfo &ci) const noexcept
TLock & GetLock() const noexcept
bool TryAcquire(const CallerInfo &ci) const noexcept
void AcquireShared(const CallerInfo &ci) const noexcept
TSharedMonoVal(std::nullptr_t) noexcept
void Reset(TArgs &&... args)
bool operator==(std::nullptr_t) const noexcept
TSharedMonoVal(TAllocator &allocator, size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent)
TSharedMonoVal & operator=(const TSharedMonoVal &other) noexcept
void Release(const CallerInfo &ci) const noexcept
static constexpr size_t SizeOfAllocation()
void SetNulled() noexcept
const T & operator*() const noexcept
const T * operator->() const noexcept
TMonoAllocator< HeapAllocator > AllocatorType
TSharedMonoVal(TSharedMonoVal &&other) noexcept
void Acquire(const CallerInfo &ci) const noexcept
TSharedMonoVal() noexcept
Default Constructor. Leaves this object nulled.
TSharedMonoVal(const TSharedMonoVal &other) noexcept
void operator=(std::nullptr_t)
Assignment of nullptr. Same as SetNulled.
T * operator->() noexcept
std::conditional_t< std::same_as< void, TLock >, FieldMembersNoLock, FieldMembersWithLock > FieldMembers
const T & Self() const noexcept
bool TryAcquireSharedTimed(const Ticks::Duration &waitDuration, const CallerInfo &ci) const noexcept
AllocatorType & GetAllocator() noexcept
TSharedMonoVal(size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent)
TSharedMonoVal & operator=(TSharedMonoVal &&other) noexcept
bool operator!=(std::nullptr_t) const noexcept
typename std::chrono::steady_clock::time_point TTimePoint
#define ALIB_HAS_METHOD(T, Method,...)
#define ALIB_STATIC_ASSERT(CondVariable, Cond, Message)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_SINGLE_THREADED
monomem::TSharedMonoVal< T, TAllocator, TLock > TSharedMonoVal
Type alias in namespace alib.
lang::CallerInfo CallerInfo
Type alias in namespace alib.
time::Ticks Ticks
Type alias in namespace alib.
FieldMembersWithLock(detail::Buffer *firstBuffer, size_t initialBufferSize, unsigned int bufferGrowthInPercent)
lang::Placeholder< T > custom
The space for the custom member. The instance will be constructed using placement-new.
std::atomic< unsigned int > refCount
The reference counter used to implement the std::shared_ptr behavior.
FieldMembersWithLock(TAllocator &pAllocator, detail::Buffer *firstBuffer, size_t initialBufferSize, unsigned int bufferGrowthInPercent)
TMonoAllocator< TAllocator > allocator
The allocator that this class is contained in.
TLock lock
The embedded lock.