14 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
17 #elif defined(_WIN32) || defined(_WIN64)
31 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
32 int result = pthread_rwlock_init(&_rwlock,
nullptr);
34 throwex SystemException(
"Failed to initialize a read/write lock!", result);
35 #elif defined(_WIN32) || defined(_WIN64)
36 InitializeSRWLock(&_rwlock);
42 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
43 int result = pthread_rwlock_destroy(&_rwlock);
45 fatality(SystemException(
"Failed to destroy a read/write lock!", result));
46 #elif defined(_WIN32) || defined(_WIN64)
53 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
54 int result = pthread_rwlock_tryrdlock(&_rwlock);
55 if ((result != 0) && (result != EAGAIN) && (result != EBUSY) && (result != EDEADLK))
56 throwex SystemException(
"Failed to try lock for read!", result);
58 #elif defined(_WIN32) || defined(_WIN64)
59 return (TryAcquireSRWLockShared(&_rwlock) != 0);
65 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
66 int result = pthread_rwlock_trywrlock(&_rwlock);
67 if ((result != 0) && (result != EAGAIN) && (result != EBUSY) && (result != EDEADLK))
68 throwex SystemException(
"Failed to try lock for write!", result);
70 #elif defined(_WIN32) || defined(_WIN64)
71 return (TryAcquireSRWLockExclusive(&_rwlock) != 0);
77 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
78 int result = pthread_rwlock_rdlock(&_rwlock);
80 throwex SystemException(
"Failed to lock for read!", result);
81 #elif defined(_WIN32) || defined(_WIN64)
82 AcquireSRWLockShared(&_rwlock);
88 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
89 int result = pthread_rwlock_wrlock(&_rwlock);
91 throwex SystemException(
"Failed to lock for write!", result);
92 #elif defined(_WIN32) || defined(_WIN64)
93 AcquireSRWLockExclusive(&_rwlock);
99 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
100 int result = pthread_rwlock_unlock(&_rwlock);
102 throwex SystemException(
"Failed to unlock read lock!", result);
103 #elif defined(_WIN32) || defined(_WIN64)
104 ReleaseSRWLockShared(&_rwlock);
110 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
111 int result = pthread_rwlock_unlock(&_rwlock);
113 throwex SystemException(
"Failed to unlock write lock!", result);
114 #elif defined(_WIN32) || defined(_WIN64)
115 ReleaseSRWLockExclusive(&_rwlock);
120 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
121 pthread_rwlock_t _rwlock;
122 #elif defined(_WIN32) || defined(_WIN64)
133 static_assert((StorageSize >=
sizeof(Impl)),
"RWLock::StorageSize must be increased!");
134 static_assert(((StorageAlign %
alignof(Impl)) == 0),
"RWLock::StorageAlign must be adjusted!");
137 new(&_storage)Impl();
143 reinterpret_cast<Impl*
>(&_storage)->~Impl();
High resolution timestamp.
void UnlockRead()
Release read lock.
void LockWrite()
Acquire write lock with block.
void UnlockWrite()
Release write lock.
bool TryLockRead()
Try to acquire read lock without block.
void LockRead()
Acquire read lock with block.
bool TryLockReadFor(const Timespan ×pan)
Try to acquire read lock for the given timespan.
bool TryLockWrite()
Try to acquire write lock without block.
bool TryLockWriteFor(const Timespan ×pan)
Try to acquire write lock for the given timespan.
static void Yield() noexcept
Yield to other threads.
Aligned storage validator.
#define throwex
Throw extended exception macro.
Fatal abort execution definition.
#define fatality(...)
Fatal abort execution extended macro.
C++ Common project definitions.
Read/Write lock synchronization primitive definition.
Aligned storage validator definition.