chsvlib
chsv helper source code

◆ chsv_mtx_init()

int Chusov::ExecutionControl::chsv_mtx_init ( chsv_mtx_t mtx,
int  nType 
)
noexcept

Creates a mutex object with the specified properties.

Parameters
[in]mtxis a pointer to a location where the function is about to store a mutex descriptor on output.
[in]nTypeis bit mask indicating a type of a mutex being created. It supports values of the chsv_mutex_constants enumeration.
Returns
The function returns chsv_thrd_success on success. On error the function returns chsv_thrd_error setting corresponding error code.

The function is implemented as an alternative to the mtx_init function defined by the ISO/IEC 9899:2011 (aka C11) standard and behaves exactly as the standard specifies. It uses own type of mutex (chsv_mtx_t), own set of possible return codes and mutex types but with respect to C11.

According to C11 the following types of a mutex object are supported:

Mutex type Description
chsv_mtx_plain A simple non-recursive mutex.
chsv_mtx_timed A non-recursive mutex with timeout support.
chsv_mtx_try A non-recursive mutex supporting test-and-run.
chsv_mtx_plain | chsv_mtx_recursive A simple recursive mutex.
chsv_mtx_timed | chsv_mtx_recursive A recursive mutex with timeout support.
chsv_mtx_try | chsv_mtx_recursive A recursive mutex supporting test-and-run.

Use the chsv_mtx_destroy function to close the created mutex and free associated resources.

See also
chsv_mtx_destroy;
chsv_mtx_lock;
chsv_mtx_unlock.