chsvlib
chsv helper source code

◆ chsv_mtx_timedlock()

int Chusov::ExecutionControl::chsv_mtx_timedlock ( chsv_mtx_t mtx,
const chsv_xtime xt 
)
noexcept

Endeavours to block until it locks the specified mutex or until the absolute time specified by the chsv_xtime object xt has passed.

Parameters
[in]mtxis a pointer to a mutex, ownership of which is to be acquired by the calling thread.
[in]xtis a pointer to chsv_xtime object specifying an absolute time when a timeout of waiting should occur.
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 reached 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 chsv_mtx_timedlock 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_timed type.

Use chsv_mtx_unlock to release the ownership of the mutex.

An absolute time is a time passed since the Epoch. See chsv_xtime_get for more details.

To specify a relative time use the chsv_mtx_timedlockfor function.

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

See also
chsv_mtx_unlock;
chsv_mtx_timedlockfor;
chsv_mtx_lock;
chsv_mtx_trylock.