16 #ifndef INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 17 #define INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ 27 #if defined(__cpp_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(__cpp_constexpr) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 110 #if defined(__cpp_constexpr) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 115 NLIB_ASSERT_NOERR(e);
121 NLIB_ASSERT_NOERR(e);
127 NLIB_ASSERT_NOERR(e);
132 NLIB_ASSERT_NOERR(e);
149 const TimeSpan& timeout) NLIB_NOEXCEPT {
151 timeout.ToTimeValue().tick, 1);
154 const TimeSpan& timeout) NLIB_NOEXCEPT {
156 timeout.ToTimeValue().tick, 1);
159 const TimeSpan& timeout) NLIB_NOEXCEPT {
161 timeout.ToTimeValue().tick, 0);
164 const TimeSpan& timeout) NLIB_NOEXCEPT {
166 timeout.ToTimeValue().tick, 0);
170 const DateTime& datetime) NLIB_NOEXCEPT {
172 datetime.ToTimeValue().tick, 1);
175 const DateTime& datetime) NLIB_NOEXCEPT {
177 datetime.ToTimeValue().tick, 1);
180 const DateTime& datetime) NLIB_NOEXCEPT {
182 datetime.ToTimeValue().tick, 0);
185 const DateTime& datetime) NLIB_NOEXCEPT {
187 datetime.ToTimeValue().tick, 0);
191 #if defined(__cpp_constexpr) && defined(NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS) 203 #endif // INCLUDE_NN_NLIB_THREADING_SHAREDCRITICALSECTION_H_ A conditional variable for SharedCriticalSection and nlib_rwlock. This variable can be used in the sa...
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.
bool try_lock_shared() noexcept NLIB_TRY_ACQUIRE_SHARED(true)
Gets the read lock, and attempts to enter the critical section.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
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...
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...
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.
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.
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().
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.
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.
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.
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.
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().
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...
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().