69template<
typename T,
typename TAllocator,
typename TLock>
81 std::atomic<unsigned> refCount;
85 size_t initialBufferSize,
86 unsigned bufferGrowthInPercent )
87 : allocator( pAllocator, firstBuffer, initialBufferSize, bufferGrowthInPercent )
90 template<
typename TRequires= TAllocator>
91 requires std::default_initializable<TRequires>
93 size_t initialBufferSize,
94 unsigned bufferGrowthInPercent )
95 : allocator(
ALIB_DBG(
"ShardMonoVal",) firstBuffer, initialBufferSize, bufferGrowthInPercent)
127 size_t initialBufferSize,
128 unsigned bufferGrowthInPercent )
129 :
allocator( pAllocator, firstBuffer, initialBufferSize, bufferGrowthInPercent )
141 template<
typename TRequires= TAllocator>
142 requires std::default_initializable<TRequires>
144 size_t initialBufferSize,
145 unsigned 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 bufferGrowthInPercent ) {
199 auto size= initialBufferSizeInKB * 1024;
206 "Initial buffer size {} to small to hold shared value of size {}.",
227 auto size= initialBufferSizeInKB * 1024;
228 void* mem= TAllocator().allocate( size,
alignof(
detail::Buffer) );
233 "Initial buffer size {} to small to hold shared value of size {}.",
243 "Template parameter TLock of class TSharedMonoVal must be <void> if module ALib Threads is "
244 "not included in the ALib Build." )
265 template<
typename... TArgs>
274 new (&
members->custom) T( std::forward<TArgs>(args)... );
289 template<
typename... TArgs>
290 void ConstructT( TArgs&&... args ) {
members->custom.Construct(std::forward<TArgs>(args)... ); }
310 const T&
Self() const noexcept { dbgassert();
return *
members->custom; }
352 :
members(other.members) { other.members=
nullptr; }
362 if (
this == &other || this->members == other.members)
372 if((
members= other.members) !=
nullptr)
395 other.members=
nullptr;
433 T*
Get() noexcept { dbgassert();
return members->custom.Get(); }
437 const T*
Get() const noexcept { dbgassert();
return members->custom.Get(); }
440 operator bool() const noexcept {
return members !=
nullptr; }
602 #elif !ALIB_SINGLE_THREADED
603 #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!");
604 template<
typename TRq= TLock>
requires (!std::same_as<TRq, void> )
605 TRq&
GetLock() const noexcept { ATPASS dbgassert();
return members->lock; }
662DOX_MARKER([DOX_MANUAL_ALIASES_SHAREDMONOVAL])
664template<
typename T,
typename TAllocator= lang::HeapAllocator,
typename TLock=
void>
666DOX_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
void ConstructT(TArgs &&... args)
void AcquireRecursive(const CallerInfo &ci) const noexcept
TLock & GetLock() const noexcept
bool TryAcquire(const CallerInfo &ci) const noexcept
unsigned UseCount() 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 & 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
TSharedMonoVal(size_t initialBufferSizeInKB, unsigned bufferGrowthInPercent)
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(TAllocator &allocator, size_t initialBufferSizeInKB, unsigned 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.
lang::Placeholder< T > custom
The space for the custom member. The instance will be constructed using placement-new.
std::atomic< unsigned > refCount
The reference counter used to implement the std::shared_ptr behavior.
FieldMembersWithLock(detail::Buffer *firstBuffer, size_t initialBufferSize, unsigned bufferGrowthInPercent)
TMonoAllocator< TAllocator > allocator
The allocator that this class is contained in.
TLock lock
The embedded lock.
FieldMembersWithLock(TAllocator &pAllocator, detail::Buffer *firstBuffer, size_t initialBufferSize, unsigned bufferGrowthInPercent)