Skip to main content

tkl_mutex | Mutex

The tkl_mutex interface creates and manages recursive mutexes for synchronized access to shared resources in a multitasking environment. It is the kernel abstraction layer (TKL) port each platform implements on top of its RTOS. Every mutex created by these functions is recursive: the owning thread can lock it more than once and must unlock it the same number of times.

Typesโ€‹

typedef void *TKL_MUTEX_HANDLE;

TKL_MUTEX_HANDLE is an opaque handle to a mutex.

tkl_mutex_create_initโ€‹

OPERATE_RET tkl_mutex_create_init(TKL_MUTEX_HANDLE *pMutexHandle);

Creates and initializes a recursive mutex.

ParameterDescription
pMutexHandleOutput parameter. Receives the created mutex handle.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

tkl_mutex_lockโ€‹

OPERATE_RET tkl_mutex_lock(const TKL_MUTEX_HANDLE mutexHandle);

Locks a recursive mutex. If the mutex is held by another thread, the calling thread blocks until it becomes available.

ParameterDescription
mutexHandleMutex handle.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

tkl_mutex_trylockโ€‹

OPERATE_RET tkl_mutex_trylock(const TKL_MUTEX_HANDLE mutexHandle);

Tries to lock a recursive mutex without blocking. Returns immediately whether or not the lock was acquired.

ParameterDescription
mutexHandleMutex handle.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

tkl_mutex_unlockโ€‹

OPERATE_RET tkl_mutex_unlock(const TKL_MUTEX_HANDLE mutexHandle);

Unlocks a recursive mutex previously locked by the calling thread.

ParameterDescription
mutexHandleMutex handle.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

tkl_mutex_releaseโ€‹

OPERATE_RET tkl_mutex_release(const TKL_MUTEX_HANDLE mutexHandle);

Releases and deletes a recursive mutex.

ParameterDescription
mutexHandleMutex handle.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

See alsoโ€‹