tkl_thread | Thread
The file tkl_thread.c
provides APIs for creating, terminating, and obtaining information about operating system threads (tasks) in a multi-tasking environment suitable for Tuya Smart devices. This file is automatically generated by the TuyaOS, with certain areas marked for developers to customize and implement relevant logic.
API Descriptionâ
tkl_thread_createâ
OPERATE_RET tkl_thread_create(TKL_THREAD_HANDLE* thread,
const char* name,
uint32_t stack_size,
uint32_t priority,
const THREAD_FUNC_T func,
void* const arg);
Functionâ
Creates a task thread.
Parametersâ
thread
: Output parameter used to return the handle of the created thread.name
: Name of the thread.stack_size
: Stack size of the thread.priority
: Priority of the thread.func
: Function pointer that the thread will execute.arg
: Argument passed to the thread function.
Return Valueâ
A return value of OPRT_OK
indicates that the thread was successfully created, while other values indicate an error. Refer to tuya_error_code.h
for specific error codes.
tkl_thread_releaseâ
OPERATE_RET tkl_thread_release(const TKL_THREAD_HANDLE thread);
Functionâ
Terminates a thread and releases its resources.
Parametersâ
thread
: Handle of the thread to be terminated.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate an error. Refer to tuya_error_code.h
for detailed information.
tkl_thread_get_watermarkâ
OPERATE_RET tkl_thread_get_watermark(const TKL_THREAD_HANDLE thread, uint32_t* watermark);
Functionâ
Obtains the highest water mark (minimum remaining stack space) of the thread stack.
Parametersâ
thread
: Thread handle.watermark
: Output parameter, the highest water mark in bytes.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate failure.
tkl_thread_get_idâ
OPERATE_RET tkl_thread_get_id(TKL_THREAD_HANDLE *thread);
Functionâ
Obtains the handle of the current thread.
Parametersâ
thread
: Output parameter, handle of the current thread.
Return Valueâ
Always returns OPRT_OK
, indicating a successful call.
tkl_thread_set_self_nameâ
OPERATE_RET tkl_thread_set_self_name(const char* name);
Functionâ
Sets the name of the current thread.
Parametersâ
name
: New name of the thread.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate an error.
tkl_thread_is_selfâ
OPERATE_RET tkl_thread_is_self(TKL_THREAD_HANDLE thread, BOOL_T* is_self);
Functionâ
Determines if the specified thread is the current thread.
Parametersâ
thread
: Thread handle.is_self
: Output parameter, indicates whether it is the current thread.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate failure.
tkl_thread_get_priorityâ
OPERATE_RET tkl_thread_get_priority(TKL_THREAD_HANDLE thread, int *priority);
Functionâ
Obtains the priority of a thread.
Parametersâ
thread
: Thread handle. If NULL, it indicates obtaining the priority of the current thread.priority
: Output parameter, used to return the thread priority.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate failure.
tkl_thread_set_priorityâ
OPERATE_RET tkl_thread_set_priority(TKL_THREAD_HANDLE thread, int priority);
Functionâ
Sets the priority of a thread.
Parametersâ
thread
: Thread handle. If NULL, it indicates setting the priority of the current thread.priority
: New priority of the thread.
Return Valueâ
A return value of OPRT_OK
indicates success, while other values indicate failure.
tkl_thread_diagnoseâ
OPERATE_RET tkl_thread_diagnose(TKL_THREAD_HANDLE thread);
Functionâ
Diagnoses a thread, such as printing task stack information.
Parametersâ
thread
: Thread handle.
Return Valueâ
A return value of OPRT_OK
indicates a successful diagnosis.