include/Cnx/sync/UniqueLock.h file

CnxUniqueLock provides an exlusive-ownership scoped mutex locking mechanism similar to C++'s std::unique_lock

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Classes

struct CnxUniqueLock
CnxUniqueLock provides scoped exclusive locking of any higher-level mutexes (eg CnxMutex, CnxSharedMutex, etc.) provided by Cnx. It allows for a simple, concise way to acquire the exclusive lock on a mutex and ensure that lock is released appropriately when the CnxUniqueLock exits scope.

Typedefs

using CnxUniqueLock = struct CnxUniqueLock
CnxUniqueLock provides scoped exclusive locking of any higher-level mutexes (eg CnxMutex, CnxSharedMutex, etc.) provided by Cnx. It allows for a simple, concise way to acquire the exclusive lock on a mutex and ensure that lock is released appropriately when the CnxUniqueLock exits scope.

Functions

void cnx_unique_lock_lock(CnxUniqueLock*restrict lock)
Acquires an exclusive lock on the mutex associated with the given CnxUniqueLock
bool cnx_unique_lock_try_lock(CnxUniqueLock*restrict lock)
Attempts to acquire an exclusive lock on the mutex associated with the given CnxUniqueLock
bool cnx_unique_lock_try_lock_for(CnxUniqueLock*restrict lock, CnxDuration duration)
Attempts to acquire an exclusive lock on the mutex associated with the given CnxUniqueLock
bool cnx_unique_lock_try_lock_until(CnxUniqueLock*restrict lock, CnxTimePoint stop_point)
Attempts to acquire an exclusive lock on the mutex associated with the given CnxUniqueLock
void cnx_unique_lock_unlock(CnxUniqueLock*restrict lock)
Unlocks the mutex associated with the given CnxUniqueLock
CnxMutexInterface cnx_unique_lock_mutex(CnxUniqueLock*restrict lock)
Returns the CnxMutexInterface Trait object corresponding with the mutex associated with the given CnxUniqueLock
bool cnx_unique_lock_owns_lock(CnxUniqueLock*restrict lock)
Returns whether the given CnxUniqueLock currently owns an exclusive lock on its associated mutex.
void cnx_unique_lock_free(void* lock)
Destroys the given CnxUniqueLock, unlocking its associated mutex if it owns a lock on it.

Defines

#define UniqueLock
Declaring a CnxUniqueLock as a UniqueLock ensures that it will be destroyed when it exits scope, releasing the lock on its associated mutex.
#define cnx_unique_lock(...)
Creates a new CnxUniqueLock associated with the given mutex.