chsvlib
chsv helper source code

◆ chsv_mtx_lock()

int Chusov::ExecutionControl::chsv_mtx_lock ( chsv_mtx_t mtx)
noexcept

Blocks the calling thread until the function locks a mutex.

Parameters
[in]mtxis a pointer to a mutex, ownership of which is to be acquired by the calling thread.
Returns
returns chsv_thrd_success on success, or chsv_thrd_busy if the resource requested is already in use, or chsv_thrd_error if the request could not be honored. In the last two cases the function sets corresponding errno code.

The chsv_mtx_lock function blocks until it locks the mutex pointed to by mtx. If the mutex is non-recursive, and is already locked by the calling thread, the function fails returning chsv_thrd_busy. Prior calls to chsv_mtx_unlock on the same mutex shall synchronize with this operation.

The mutex must be of chsv_mtx_plain type.

Use chsv_mtx_unlock to release the ownership of the mutex.

The function implements a behaviour of the mtx_lock function defined in the ISO/IEC 9899:2011 (aka C11) standard.

See also
chsv_mtx_unlock;
chsv_mtx_timedlock;
chsv_mtx_timedlockfor;
chsv_mtx_trylock.