3 #ifndef INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 4 #define INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 14 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 36 NLIB_ASSERT(e == 0 || e == EBUSY);
40 NLIB_TRY_ACQUIRE_SHARED(
true) {
42 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
46 NLIB_TRY_ACQUIRE_SHARED(
true) {
48 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
57 void lock() NLIB_NOEXCEPT NLIB_ACQUIRE() {
64 NLIB_ASSERT(e == 0 || e == EBUSY);
68 NLIB_NOEXCEPT NLIB_TRY_ACQUIRE(
true) {
70 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
74 NLIB_NOEXCEPT NLIB_TRY_ACQUIRE(
true) {
76 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
79 void unlock() NLIB_NOEXCEPT NLIB_RELEASE() {
86 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 96 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 101 NLIB_ASSERT_NOERR(e);
107 NLIB_ASSERT_NOERR(e);
113 NLIB_ASSERT_NOERR(e);
118 NLIB_ASSERT_NOERR(e);
135 const TimeSpan& timeout) NLIB_NOEXCEPT {
137 timeout.ToTimeValue().tick, 1);
140 const TimeSpan& timeout) NLIB_NOEXCEPT {
142 timeout.ToTimeValue().tick, 1);
145 const TimeSpan& timeout) NLIB_NOEXCEPT {
147 timeout.ToTimeValue().tick, 0);
150 const TimeSpan& timeout) NLIB_NOEXCEPT {
152 timeout.ToTimeValue().tick, 0);
156 const DateTime& datetime) NLIB_NOEXCEPT {
158 datetime.ToTimeValue().tick, 1);
161 const DateTime& datetime) NLIB_NOEXCEPT {
163 datetime.ToTimeValue().tick, 1);
166 const DateTime& datetime) NLIB_NOEXCEPT {
168 datetime.ToTimeValue().tick, 0);
171 const DateTime& datetime) NLIB_NOEXCEPT {
173 datetime.ToTimeValue().tick, 0);
177 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 188 #endif // INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ A conditional variable for SharedCriticalSection and nlib_rwlock. This variable can be used in the sa...
NLIB_CHECK_RESULT errno_t WaitFor(nlib_rwlock &lock, const TimeSpan &timeout) noexcept
Unlocks a write lock and waits for a conditional variable signal for a specified period. Also see nlib_condrwlock_wait_for().
void lock_shared() noexcept NLIB_ACQUIRE_SHARED()
Gets the read lock, and enters the critical section. Blocks until it can get a lock.
NLIB_CHECK_RESULT bool try_lock_shared() noexcept NLIB_TRY_ACQUIRE_SHARED(true)
Gets the read lock, and attempts to enter the critical section.
NLIB_CHECK_RESULT bool try_lock_until(const DateTime &abstime) noexcept NLIB_TRY_ACQUIRE(true)
Gets a write lock, and attempts to enter the critical section. Times out.
~CondVarForSharedCriticalSection() noexcept
Destructor.
void Notify() noexcept
Signals to at least one waiting thread. Also see nlib_condrwlock_signal().
errno_t WaitReader(SharedCriticalSection &lock) noexcept
Unlocks the read lock and waits for a signal from the condition variable. Also see nlib_condrwlock_wa...
NLIB_CHECK_RESULT errno_t WaitUntil(SharedCriticalSection &lock, const DateTime &datetime) noexcept
Unlocks a write lock and waits for a conditional variable signal until specified date and time...
NLIB_CHECK_RESULT errno_t WaitReaderFor(nlib_rwlock &lock, const TimeSpan &timeout) noexcept
Unlocks a read lock and waits for a conditional variable signal for a specified period. Also see nlib_condrwlock_wait_for().
The class for representing the date and time.
NLIB_CHECK_RESULT errno_t WaitReaderFor(SharedCriticalSection &lock, const TimeSpan &timeout) noexcept
Unlocks a read lock and waits for a conditional variable signal for a specified period. Also see nlib_condrwlock_wait_for().
Implements a read/write lock. Used when multiple threads simultaneously read data, and a single thread writes data.
NLIB_CHECK_RESULT bool try_lock() noexcept NLIB_TRY_ACQUIRE(true)
Gets a write lock, and attempts to enter the critical section.
errno_t WaitReader(nlib_rwlock &lock) noexcept
Unlocks the read lock and waits for a signal from the condition variable. Also see nlib_condrwlock_wa...
errno_t Wait(SharedCriticalSection &lock) noexcept
Unlocks a write lock and waits for a conditional variable signal. Also see nlib_condrwlock_wait().
NLIB_CHECK_RESULT errno_t WaitReaderUntil(nlib_rwlock &lock, const DateTime &datetime) noexcept
Unlocks a read lock and waits for a conditional variable signal until specified date and time...
Defines the class for handling times and durations.
errno_t Wait(nlib_rwlock &lock) noexcept
Unlocks a write lock and waits for a conditional variable signal. Also see nlib_condrwlock_wait().
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
A file that contains the configuration information for each development environment.
void unlock_shared() noexcept NLIB_RELEASE_SHARED()
Releases the read lock.
NLIB_CHECK_RESULT errno_t WaitUntil(nlib_rwlock &lock, const DateTime &datetime) noexcept
Unlocks a write lock and waits for a conditional variable signal until specified date and time...
void unlock() noexcept NLIB_RELEASE()
Releases a write lock.
NLIB_CHECK_RESULT bool try_lock_shared_for(const TimeSpan &timeout) noexcept NLIB_TRY_ACQUIRE_SHARED(true)
Gets the read lock, and attempts to enter the critical section. Times out.
void lock() noexcept NLIB_ACQUIRE()
Gets a write lock, and enters the critical section. Blocks until it can get a lock.
NLIB_CHECK_RESULT bool try_lock_shared_until(const DateTime &abstime) noexcept NLIB_TRY_ACQUIRE_SHARED(true)
Gets the read lock, and attempts to enter the critical section. Times out.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
The class for representing the time.
NLIB_CHECK_RESULT errno_t WaitFor(SharedCriticalSection &lock, const TimeSpan &timeout) noexcept
Unlocks a write lock and waits for a conditional variable signal for a specified period. Also see nlib_condrwlock_wait_for().
NLIB_CHECK_RESULT errno_t WaitReaderUntil(SharedCriticalSection &lock, const DateTime &datetime) noexcept
Unlocks a read lock and waits for a conditional variable signal until specified date and time...
NLIB_CHECK_RESULT bool try_lock_for(const TimeSpan &timeout) noexcept NLIB_TRY_ACQUIRE(true)
Gets a write lock, and attempts to enter the critical section. Times out.
void NotifyAll() noexcept
Signals all waiting threads. Also see nlib_condrwlock_broadcast().