16 #ifndef INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 17 #define INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 27 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 49 NLIB_ASSERT(e == 0 || e == EBUSY);
53 NLIB_TRY_ACQUIRE_SHARED(
true) {
55 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
59 NLIB_TRY_ACQUIRE_SHARED(
true) {
61 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
70 void lock() NLIB_NOEXCEPT NLIB_ACQUIRE() {
77 NLIB_ASSERT(e == 0 || e == EBUSY);
81 NLIB_NOEXCEPT NLIB_TRY_ACQUIRE(
true) {
83 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
87 NLIB_NOEXCEPT NLIB_TRY_ACQUIRE(
true) {
89 NLIB_ASSERT(e == 0 || e == ETIMEDOUT);
92 void unlock() NLIB_NOEXCEPT NLIB_RELEASE() {
99 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 109 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 114 NLIB_ASSERT_NOERR(e);
120 NLIB_ASSERT_NOERR(e);
126 NLIB_ASSERT_NOERR(e);
131 NLIB_ASSERT_NOERR(e);
148 const TimeSpan& timeout) NLIB_NOEXCEPT {
150 timeout.ToTimeValue().tick, 1);
153 const TimeSpan& timeout) NLIB_NOEXCEPT {
155 timeout.ToTimeValue().tick, 1);
158 const TimeSpan& timeout) NLIB_NOEXCEPT {
160 timeout.ToTimeValue().tick, 0);
163 const TimeSpan& timeout) NLIB_NOEXCEPT {
165 timeout.ToTimeValue().tick, 0);
169 const DateTime& datetime) NLIB_NOEXCEPT {
171 datetime.ToTimeValue().tick, 1);
174 const DateTime& datetime) NLIB_NOEXCEPT {
176 datetime.ToTimeValue().tick, 1);
179 const DateTime& datetime) NLIB_NOEXCEPT {
181 datetime.ToTimeValue().tick, 0);
184 const DateTime& datetime) NLIB_NOEXCEPT {
186 datetime.ToTimeValue().tick, 0);
190 #if defined(NLIB_CXX11_CONSTEXPR) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 201 #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().