WS63 SDK 文档 7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
Mutex
Mutex 的协作图:

结构体

struct  MuxBaseCB
 

宏定义

#define LOS_ERRNO_MUX_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x00)
 
#define LOS_ERRNO_MUX_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x01)
 
#define LOS_ERRNO_MUX_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x02)
 
#define LOS_ERRNO_MUX_ALL_BUSY   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x03)
 
#define LOS_ERRNO_MUX_UNAVAILABLE   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x04)
 
#define LOS_ERRNO_MUX_PEND_INTERR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
 
#define LOS_ERRNO_MUX_PEND_IN_LOCK   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x06)
 
#define LOS_ERRNO_MUX_TIMEOUT   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x07)
 
#define LOS_ERRNO_MUX_OVERFLOW   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x08)
 
#define LOS_ERRNO_MUX_PENDED   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x09)
 
#define LOS_ERRNO_MUX_GET_COUNT_ERR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)
 
#define LOS_ERRNO_MUX_REG_ERROR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)
 
#define LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)
 

函数

UINT32 LOS_MuxCreate (UINT32 *muxHandle)
 Create a mutex.
 
UINT32 LOS_MuxDelete (UINT32 muxHandle)
 Delete a mutex.
 
UINT32 LOS_MuxPend (UINT32 muxHandle, UINT32 timeout)
 Wait to lock a mutex.
 
UINT32 LOS_MuxPost (UINT32 muxHandle)
 Release a mutex.
 

详细描述

宏定义说明

◆ LOS_ERRNO_MUX_ALL_BUSY

#define LOS_ERRNO_MUX_ALL_BUSY   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x03)

Mutex error code: No mutex is available and the mutex request fails.

Value: 0x02001d03.

Solution: Increase the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.

◆ LOS_ERRNO_MUX_GET_COUNT_ERR

#define LOS_ERRNO_MUX_GET_COUNT_ERR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)

The error code is not in use temporarily.

Value: 0x02001d0A

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_MUX_INVALID

#define LOS_ERRNO_MUX_INVALID   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x01)

Mutex error code: The mutex is not usable.

Value: 0x02001d01.

Solution: Check whether the mutex ID and the mutex state are applicable for the current operation.

◆ LOS_ERRNO_MUX_NO_MEMORY

#define LOS_ERRNO_MUX_NO_MEMORY   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x00)

Mutex error code: The memory request fails.

Value: 0x02001d00.

Solution: Decrease the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.

◆ LOS_ERRNO_MUX_OVERFLOW

#define LOS_ERRNO_MUX_OVERFLOW   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x08)

The error code is not in use temporarily.

Value: 0x02001d08

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_MUX_PEND_IN_LOCK

#define LOS_ERRNO_MUX_PEND_IN_LOCK   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x06)

Mutex error code: A thread locks a mutex after waiting for the mutex to be unlocked by another thread when the task scheduling is disabled.

Value: 0x02001d06.

Solution: Check whether the task scheduling is disabled, or set timeout to 0, which means that the thread will not wait for the mutex to become available.

◆ LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK

#define LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)

Mutex error code: The mutex is being locked in system-level task. old usage: The mutex is being locked in software timer task(LOS_ERRNO_MUX_PEND_IN_SWTMR_TSK).

Value: 0x02001d0C.

Solution: Pend the mutex in a valid task.

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_MUX_PEND_INTERR

#define LOS_ERRNO_MUX_PEND_INTERR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)

Mutex error code: The mutex is being locked during an interrupt.

Value: 0x02001d05.

Solution: Check whether the mutex is being locked during an interrupt.

◆ LOS_ERRNO_MUX_PENDED

#define LOS_ERRNO_MUX_PENDED   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x09)

Mutex error code: The mutex to be deleted is being locked.

Value: 0x02001d09.

Solution: Delete the mutex after it is unlocked.

◆ LOS_ERRNO_MUX_PTR_NULL

#define LOS_ERRNO_MUX_PTR_NULL   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x02)

Mutex error code: Null pointer.

Value: 0x02001d02.

Solution: Check whether the input parameter is usable.

◆ LOS_ERRNO_MUX_REG_ERROR

#define LOS_ERRNO_MUX_REG_ERROR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)

The error code is not in use temporarily.

Value: 0x02001d0B

弃用:
This error code is obsolete since LiteOS 5.0.0.

◆ LOS_ERRNO_MUX_TIMEOUT

#define LOS_ERRNO_MUX_TIMEOUT   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x07)

Mutex error code: The mutex locking times out.

Value: 0x02001d07.

Solution: Increase the waiting time or set the waiting time to LOS_WAIT_FOREVER (forever-blocking mode).

◆ LOS_ERRNO_MUX_UNAVAILABLE

#define LOS_ERRNO_MUX_UNAVAILABLE   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x04)

Mutex error code: The mutex fails to be locked in non-blocking mode because it is locked by another thread.

Value: 0x02001d04.

Solution: Lock the mutex after it is unlocked by the thread that owns it, or set a waiting time.

函数说明

◆ LOS_MuxCreate()

UINT32 LOS_MuxCreate ( UINT32 muxHandle)
extern

Create a mutex.

Description:
This API is used to create a mutex. A mutex handle is assigned to muxHandle when the mutex is created successfully. Return LOS_OK when creating is successful, return specific error code otherwise.
注意
The total number of mutexes is pre-configured. If there are no available mutexes, the mutex creation will fail.
参数
muxHandle[OUT] Handle pointer of the successfully created mutex. The value of handle should be in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
返回值
LOS_ERRNO_MUX_PTR_NULLThe muxHandle pointer is NULL.
LOS_ERRNO_MUX_ALL_BUSYNo available mutex.
LOS_OKThe mutex is successfully created.
Dependency:
  • los_mux.h: the header file that contains the API declaration.
参见
LOS_MuxDelete
自从
Huawei LiteOS V100R001C00

◆ LOS_MuxDelete()

UINT32 LOS_MuxDelete ( UINT32  muxHandle)
extern

Delete a mutex.

Description:
This API is used to delete a specified mutex. Return LOS_OK if the mutex deletion is successfully, otherwise return specific error code.
注意
  • The specific mutex should be created firstly.
  • The mutex can be deleted successfully only when there is no other tasks pend on it.
参数
muxHandle[IN] The mutex handle to be deleted. The value of handle should be in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
返回值
LOS_ERRNO_MUX_INVALIDInvalid handle or mutex in use.
LOS_ERRNO_MUX_PENDEDTasks pended on this mutex.
LOS_OKThe mutex is successfully deleted.
Dependency:
  • los_mux.h: the header file that contains the API declaration.
参见
LOS_MuxCreate
自从
Huawei LiteOS V100R001C00

◆ LOS_MuxPend()

UINT32 LOS_MuxPend ( UINT32  muxHandle,
UINT32  timeout 
)
extern

Wait to lock a mutex.

Description:
This API is used to wait for a specified period of time to lock a mutex.
注意
  • The specific mutex should be created firstly.
  • The function fails if the mutex that is waited on is already locked by another thread when the task scheduling is disabled.
  • Do not wait on a mutex during an interrupt.
  • The priority inheritance protocol is supported. If a higher-priority thread is waiting on a mutex, it changes the priority of the thread that owns the mutex to avoid priority inversion.
  • A recursive mutex can be locked more than once by the same thread.
  • Do not recommend to use this API in software timer callback.
参数
muxHandle[IN] The mutex handle to be waited for. The value of handle should be in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
timeout[IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
返回值
LOS_ERRNO_MUX_INVALIDThe mutex state (for example, the mutex does not exist or is not in use) is not applicable for the current operation.
LOS_ERRNO_MUX_UNAVAILABLEThe mutex fails to be locked because it is locked by another thread and a period of time is not set for waiting for the mutex to become available.
LOS_ERRNO_MUX_PEND_INTERRThe mutex is being locked during an interrupt.
LOS_ERRNO_MUX_PEND_IN_LOCKThe mutex is waited on when the task scheduling is disabled.
LOS_ERRNO_MUX_TIMEOUTThe mutex waiting times out.
LOS_OKThe mutex is successfully locked.
Dependency:
  • los_mux.h: the header file that contains the API declaration.
参见
LOS_MuxCreate | LOS_MuxPost
自从
Huawei LiteOS V100R001C00

◆ LOS_MuxPost()

UINT32 LOS_MuxPost ( UINT32  muxHandle)
extern

Release a mutex.

Description:
This API is used to release a specified mutex.
注意
  • The specific mutex should be created firstly.
  • Do not release a mutex during an interrupt.
  • If a recursive mutex is locked for many times, it must be unlocked for the same times to be released.
参数
muxHandle[IN] The mutex handle to be released. The value of handle should be in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
返回值
LOS_ERRNO_MUX_INVALIDThe mutex state (for example, the mutex does not exist or is not in use or owned by other thread) is not applicable for the current operation.
LOS_ERRNO_MUX_PEND_INTERRThe mutex is being released during an interrupt.
LOS_OKThe mutex is successfully released.
Dependency:
  • los_mux.h: the header file that contains the API declaration.
参见
LOS_MuxCreate | LOS_MuxPend
自从
Huawei LiteOS V100R001C00