Skip to main content

tkl_semaphore | Semaphore

The tkl_semaphore interface creates and manages counting semaphores for task synchronization and event notification in a multitasking environment. It is the kernel abstraction layer (TKL) port each platform implements on top of its RTOS.

Types

typedef void *TKL_SEM_HANDLE;
#define TKL_SEM_WAIT_FOREVER 0xFFFFffff
SymbolDescription
TKL_SEM_HANDLEOpaque handle to a semaphore.
TKL_SEM_WAIT_FOREVERTimeout value for tkl_semaphore_wait that blocks until the semaphore is acquired.

tkl_semaphore_create_init

OPERATE_RET tkl_semaphore_create_init(TKL_SEM_HANDLE *handle, uint32_t sem_cnt, uint32_t sem_max);

Creates and initializes a counting semaphore.

ParameterDescription
handleOutput parameter. Receives the created semaphore handle.
sem_cntInitial count of the semaphore.
sem_maxMaximum count of the semaphore.
  • Return value: OPRT_OK on success. Any other value indicates an error; see tuya_error_code.h.

tkl_semaphore_wait

OPERATE_RET tkl_semaphore_wait(const TKL_SEM_HANDLE handle, uint32_t timeout);

Waits on a semaphore, decrementing its count when one is acquired.

ParameterDescription
handleSemaphore handle.
timeoutWait timeout in milliseconds. TKL_SEM_WAIT_FOREVER blocks until the semaphore is acquired.
  • Return value: OPRT_OK on success. OPRT_OS_ADAPTER_SEM_WAIT_TIMEOUT indicates a timeout. Any other value indicates an error; see tuya_error_code.h.

tkl_semaphore_post

OPERATE_RET tkl_semaphore_post(const TKL_SEM_HANDLE handle);

Posts (signals) a semaphore, incrementing its count.

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

tkl_semaphore_release

OPERATE_RET tkl_semaphore_release(const TKL_SEM_HANDLE handle);

Releases and deletes a semaphore.

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

See also