Skip to main content

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's smart devices. This file is automatically generated by the TuyaOS and includes designated areas for you to customize and implement related 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);
  • Feature: Creates a task thread.

  • Parameters:

    • thread: The output parameter used to return the handle of the created thread.
    • name: The name of the thread.
    • stack_size: The stack size of the thread.
    • priority: The priority of the thread.
    • func: The pointer to the function executed by the thread.
    • arg: The argument passed to the thread function.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_release

OPERATE_RET tkl_thread_release(const TKL_THREAD_HANDLE thread);
  • Feature: Terminates a thread and releases its resources.

  • Parameter: thread, the handle of the thread to be terminated.

  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_get_watermark

OPERATE_RET tkl_thread_get_watermark(const TKL_THREAD_HANDLE thread, uint32_t* watermark);
  • Feature: Gets the highest watermark (minimum remaining stack space) of the thread stack.

  • Parameters:

    • thread: The handle to a thread.
    • watermark: The output parameter for the highest watermark value in bytes.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_get_id

OPERATE_RET tkl_thread_get_id(TKL_THREAD_HANDLE *thread);
  • Feature: Gets the handle of the current thread.

  • Parameter: thread, an output parameter for the current thread handle.

  • 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);
  • Feature: Sets the name of the current thread.

  • Parameter: name, the new name for the thread.

  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_is_self

OPERATE_RET tkl_thread_is_self(TKL_THREAD_HANDLE thread, BOOL_T* is_self);
  • Feature: Determines whether the specified thread is the current thread.

  • Parameters:

    • thread: The handle to a thread.
    • is_self: The output parameter indicating whether it is the current thread.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_get_priority

OPERATE_RET tkl_thread_get_priority(TKL_THREAD_HANDLE thread, int *priority);
  • Feature: Gets the priority of a thread.

  • Parameters:

    • thread: The handle to a thread. If the value is NULL, get the priority of the current thread.
    • priority: The output parameter for returning the thread priority.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_set_priority

OPERATE_RET tkl_thread_set_priority(TKL_THREAD_HANDLE thread, int priority);
  • Feature: Sets the priority of a thread.
  • Parameters:
    • thread: The handle to a thread. If the value is NULL, set the priority of the current thread.
    • priority: The new priority of the thread.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.

tkl_thread_diagnose

OPERATE_RET tkl_thread_diagnose(TKL_THREAD_HANDLE thread);
  • Feature: Diagnoses a thread, such as printing task stack information.
  • Parameter: thread, the handle of the thread.
  • Return value: OPRT_OK indicates a success. Any other value indicates an error. For detailed error codes, refer to tuya_error_code.h.