chsvlib
chsv helper source code

◆ chsv_mtx_trylock()

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

Endeavors to lock the specified mutex and returns without blocking even if the mutex ownership cannot be acquired.

Parameters
[in]mtxis a pointer to a mutex, ownership of which is to be acquired by the calling thread.
Returns
On success the function returns chsv_thrd_success. The function can also fail with chsv_thrd_busy if the mutex requested is already in use, or chsv_thrd_timeout if the time specified was elapsed without acquiring the mutex, or chsv_thrd_error if the request could not be honored because of any other error. In these case the failure reason is also specified by the errno code the function sets.

The function endeavors to lock the mutex pointed to by mtx. The specified mutex shall support either test and return or timeout. If the mutex is already locked, the function returns without blocking. If the operation succeeds, prior calls to chsv_mtx_unlock on the same mutex shall synchronize with this operation.

The mutex must be of either chsv_mtx_try or chsv_mtx_timed type.

Use chsv_mtx_unlock to release the ownership of the mutex.

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

See also
chsv_mtx_unlock;
chsv_mtx_lock;
chsv_mtx_timedlockfor;
chsv_mtx_timedlock.