chsvlib
chsv helper source code

◆ chsv_mtx_timedlockfor()

int Chusov::ExecutionControl::chsv_mtx_timedlockfor ( chsv_mtx_t mtx,
unsigned long  cMilliseconds 
)
noexcept

Endeavors to block until it locks the specified mutex or until the time, specified in milliseconds elapses.

Parameters
[in]mtxis a pointer to a mutex, ownership of which is to be acquired by the calling thread.
[in]cMillisecondsis a whole number of milliseconds for the function to wait for the mutex ownership to be granted.
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 chsv_mtx_timedlockfor 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.

This is an extension to the chsv_mtx_timedlock function which implements waiting for an absolute time specified as chsv_xtime object as specified by the C11 standard. The chsv_mtx_timedlockfor function uses a relative time passed since the moment of a call.

See also
chsv_mtx_unlock;
chsv_mtx_timedlock;
chsv_mtx_lock;
chsv_mtx_trylock.