9#ifndef HPP_ALIB_LANG_OWNER
10#define HPP_ALIB_LANG_OWNER 1
18namespace alib {
namespace lang {
47template <
typename TOwnable>
61 template<
typename TEnableIf= TOwnable,
66 template<
typename TEnableIf= TOwnable,
68 void callRelease() {
owned.Release(); }
78 ,
dbgCI(ci) { ownable.Acquire( ci ); }
80 Owner( TOwnable& ownable ) :
owned(ownable) { ownable.Acquire(); }
94template <
typename TOwnable>
109 template<
typename TEnableIf= TOwnable,
114 template<
typename TEnableIf= TOwnable,
116 void callRelease() {
owned.Release(); }
119 template<
typename TEnableIf= TOwnable,
121 void callRelease() {
owned.ReleaseRecursive(
dbgCI); }
124 template<
typename TEnableIf= TOwnable,
126 void callRelease() {
owned.ReleaseRecursive(); }
158template <
typename TOwnable>
173 template<
typename TEnableIf= TOwnable,
178 template<
typename TEnableIf= TOwnable,
180 void callRelease() {
owned.Release(); }
184 template<
typename TEnableIf= TOwnable,
186 void callRelease() {
owned.ReleaseRecursive(
dbgCI); }
189 template<
typename TEnableIf= TOwnable,
191 void callRelease() {
owned.ReleaseRecursive(); }
205 template<
typename TTimeValue>
210 template<
typename TTimeValue>
211 OwnerTimed( TOwnable& ownable,
const TTimeValue& time )
212 :
owned(ownable) {
isOwning= ownable.TryAcquireTimed( time ); }
232template <
typename TOwnable>
246 template<
typename TEnableIf= TOwnable,
248 void callRelease() {
owned.ReleaseRecursive(
dbgCI); }
251 template<
typename TEnableIf= TOwnable,
253 void callRelease() {
owned.ReleaseRecursive(); }
263 ,
dbgCI(ci) { ownable.AcquireRecursive(ci); }
280template <
typename TOwnable>
294 template<
typename TEnableIf= TOwnable,
296 void callRelease()
const {
owned.ReleaseShared(
dbgCI); }
299 template<
typename TEnableIf= TOwnable,
301 void callRelease()
const {
owned.ReleaseShared(); }
311 ,
dbgCI(ci) { ownable.AcquireShared(ci); }
313 OwnerShared( TOwnable& ownable ) :
owned(ownable) { ownable.AcquireShared(); }
329template <
typename TOwnable>
344 template<
typename TEnableIf= TOwnable,
346 void callRelease() {
owned.ReleaseShared(
dbgCI); }
349 template<
typename TEnableIf= TOwnable,
351 void callRelease() {
owned.ReleaseShared(); }
385template <
typename TOwnable>
400 template<
typename TEnableIf= TOwnable,
402 void callRelease() {
owned.ReleaseShared(
dbgCI); }
405 template<
typename TEnableIf= TOwnable,
407 void callRelease() {
owned.ReleaseShared(); }
420 template<
typename TTimeValue>
423 ,
dbgCI(ci) {
isOwning= ownable.TryAcquireSharedTimed( time, ci); }
425 template<
typename TTimeValue>
427 :
owned(ownable) {
isOwning= ownable.TryAcquireSharedTimed( time ); }
447#define ALIB_OWN( ownable) alib::lang::Owner <decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
448#define ALIB_OWN_RECURSIVE(ownable) alib::lang::OwnerRecursive<decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
449#define ALIB_OWN_SHARED( ownable) alib::lang::OwnerShared <decltype(ownable)> ALIB_IDENTIFIER(owner) (ownable ALIB_COMMA_CALLER_PRUNED);
453# define ALIB_LOCK ALIB_OWN(*this)
454# define ALIB_LOCK_RECURSIVE ALIB_OWN_RECURSIVE(*this)
455# define ALIB_LOCK_SHARED ALIB_OWN_SHARED(*this)
456# define ALIB_LOCK_WITH(lock) ALIB_OWN(lock)
457# define ALIB_LOCK_RECURSIVE_WITH(lock) ALIB_OWN_RECURSIVE(lock)
458# define ALIB_LOCK_SHARED_WITH(lock) ALIB_OWN_SHARED(lock)
461# define ALIB_LOCK { alib::DbgAssertSingleThreaded(); }
462# define ALIB_LOCK_RECURSIVE { alib::DbgAssertSingleThreaded(); }
463# define ALIB_LOCK_SHARED { alib::DbgAssertSingleThreaded(); }
464# define ALIB_LOCK_WITH(VOID) { alib::DbgAssertSingleThreaded(); }
465# define ALIB_LOCK_RECURSIVE_WITH(VOID) { alib::DbgAssertSingleThreaded(); }
466# define ALIB_LOCK_SHARED_WITH(VOID) { alib::DbgAssertSingleThreaded(); }
469# define ALIB_LOCK_RECURSIVE {}
470# define ALIB_LOCK_SHARED {}
471# define ALIB_LOCK_WITH(VOID) {}
472# define ALIB_LOCK_RECURSIVE_WITH(VOID) {}
473# define ALIB_LOCK_SHARED_WITH(VOID) {}
480#define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS_MEMBER_DECL \
481bool dbgRecursionDetectionFlag = false;
483#define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS \
484struct RecursionDetection \
487 RecursionDetection( bool& testMember ) : TestMember(testMember) {} \
489 void Acquire( const lang::CallerInfo& ci ) \
491 ALIB_ASSERT_ERROR(TestMember==false,"FSOWNER","Forbidden recursive use of method ", ci.Func)\
494 void Release() { TestMember= false; } \
496RecursionDetection dbgRecursionDetection( dbgRecursionDetectionFlag ); \
497ALIB_OWN(dbgRecursionDetection);
499# define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS_MEMBER_DECL
500# define ALIB_DBG_PREVENT_RECURSIVE_METHOD_CALLS
CallerInfo dbgCI
Caller information. Available only with debug-builds.
OwnerRecursive(TOwnable &ownable, const CallerInfo &ci)
~OwnerRecursive()
Destructor. Invokes ReleaseRecursive() on member owned.
TOwnable & owned
The resource to acquire and release.
CallerInfo dbgCI
Caller information. Available only with debug-builds.
bool isOwning
The result of the call to TryAcquire.
bool IsOwning() const noexcept
TOwnable & owned
The resource to acquire and release.
~OwnerSharedTimed()
Destructor. Invokes Release() on member owned.
OwnerSharedTimed(TOwnable &ownable, const TTimeValue &time, const CallerInfo &ci)
OwnerShared(TOwnable &ownable, const CallerInfo &ci)
CallerInfo dbgCI
Caller information. Available only with debug-builds.
~OwnerShared()
Destructor. Invokes ReleaseShared() on member owned.
TOwnable & owned
The resource to acquire and release.
CallerInfo dbgCI
Caller information. Available only with debug-builds.
OwnerTimed(TOwnable &ownable, const TTimeValue &time, const CallerInfo &ci)
bool isOwning
The result of the call to TryAcquire.
bool IsOwning() const noexcept
TOwnable & owned
The resource to acquire and release.
~OwnerTimed()
Destructor. Invokes Release() on member owned.
CallerInfo dbgCI
Caller information. Available only with debug-builds.
bool isOwning
The result of the call to TryAcquire.
OwnerTryShared(TOwnable &ownable, const CallerInfo &ci)
~OwnerTryShared()
Destructor. Invokes Release() on member owned.
bool IsOwning() const noexcept
TOwnable & owned
The resource to acquire and release.
CallerInfo dbgCI
Caller information. Available only with debug-builds.
bool isOwning
The result of the call to TryAcquire.
OwnerTry(TOwnable &ownable, const CallerInfo &ci)
bool IsOwning() const noexcept
TOwnable & owned
The resource to acquire and release.
~OwnerTry()
Destructor. Invokes Release() on member owned.
CallerInfo dbgCI
Caller information. Available only with debug-builds.
Owner(TOwnable &ownable, const CallerInfo &ci)
TOwnable & owned
The resource to acquire and release.
~Owner()
Destructor. Releases the owner by invoking Release().
#define ALIB_STACK_ALLOCATED_TYPE(T)
#define ATMP_HAS_METHOD(T, Method,...)
#define ATMP_T_IF(T, Cond)