tkl_mutex | Mutex Lock
The file tkl_mutex.c is used for creating and managing mutexes. In embedded systems or multi-tasking operating systems, it ensures synchronized access to resources. The functions defined in this file can create mutexes, lock them, attempt to lock them, unlock them, and destroy them. This file is automatically generated by TuyaOS and allows you to add or modify code implementations in specified areas.
API description
tkl_mutex_create_init
OPERATE_RET tkl_mutex_create_init(TKL_MUTEX_HANDLE *handle);
-
Feature: Creates and initializes a mutex.
-
Parameter:
handleis an output parameter used to store the created mutex handle. -
Return value:
OPRT_OKindicates that a mutex was successfully created. Any other value indicates an error. For detailed error codes, refer totuya_error_code.h.
tkl_mutex_lock
OPERATE_RET tkl_mutex_lock(const TKL_MUTEX_HANDLE handle);
-
Feature: Locks a mutex. If the mutex is already locked by another task, the calling task will be suspended until the mutex becomes available.
-
Parameter:
handleis an input parameter representing the mutex handle. -
Return value:
OPRT_OKindicates that the mutex was successfully locked. An error code is returned on failure. For detailed error codes, refer totuya_error_code.h.
tkl_mutex_trylock
OPERATE_RET tkl_mutex_trylock(const TKL_MUTEX_HANDLE mutexHandle);
-
Feature: Attempts to lock a mutex but will not suspend the calling task if the mutex is already held.
-
Parameter:
mutexHandleis an input parameter representing the mutex handle. -
Return value:
OPRT_OKindicates that the mutex was successfully attempted to be locked. Any other value indicates an error. For detailed error codes, refer totuya_error_code.h.
tkl_mutex_unlock
OPERATE_RET tkl_mutex_unlock(const TKL_MUTEX_HANDLE handle);
-
Feature: Unlocks a previously locked mutex.
-
Parameter:
handleis an input parameter representing the mutex handle. -
Return value:
OPRT_OKindicates that a mutex was successfully unlocked. Any other value indicates an error. For detailed error codes, refer totuya_error_code.h.
tkl_mutex_release
OPERATE_RET tkl_mutex_release(const TKL_MUTEX_HANDLE handle);
-
Feature: Releases and deletes a mutex.
-
Parameter:
handleis an input parameter representing the mutex handle. -
Return value:
OPRT_OKindicates that the resources were successfully released. Any other value indicates an error. For detailed error codes, refer totuya_error_code.h.