xref: /kernel/liteos_m/kernel/include/los_mux.h (revision 3d8536b4)
13d8536b4Sopenharmony_ci/*
23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
43d8536b4Sopenharmony_ci *
53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met:
73d8536b4Sopenharmony_ci *
83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
93d8536b4Sopenharmony_ci *    conditions and the following disclaimer.
103d8536b4Sopenharmony_ci *
113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
123d8536b4Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
133d8536b4Sopenharmony_ci *    provided with the distribution.
143d8536b4Sopenharmony_ci *
153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
163d8536b4Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
173d8536b4Sopenharmony_ci *    permission.
183d8536b4Sopenharmony_ci *
193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303d8536b4Sopenharmony_ci */
313d8536b4Sopenharmony_ci
323d8536b4Sopenharmony_ci/**
333d8536b4Sopenharmony_ci * @defgroup los_mux Mutex
343d8536b4Sopenharmony_ci * @ingroup kernel
353d8536b4Sopenharmony_ci */
363d8536b4Sopenharmony_ci
373d8536b4Sopenharmony_ci#ifndef _LOS_MUX_H
383d8536b4Sopenharmony_ci#define _LOS_MUX_H
393d8536b4Sopenharmony_ci
403d8536b4Sopenharmony_ci#include "los_task.h"
413d8536b4Sopenharmony_ci
423d8536b4Sopenharmony_ci#ifdef __cplusplus
433d8536b4Sopenharmony_ci#if __cplusplus
443d8536b4Sopenharmony_ciextern "C" {
453d8536b4Sopenharmony_ci#endif /* __cplusplus */
463d8536b4Sopenharmony_ci#endif /* __cplusplus */
473d8536b4Sopenharmony_ci
483d8536b4Sopenharmony_ci/**
493d8536b4Sopenharmony_ci * @ingroup los_mux
503d8536b4Sopenharmony_ci * Mutex error code: The memory request fails.
513d8536b4Sopenharmony_ci *
523d8536b4Sopenharmony_ci * Value: 0x02001d00
533d8536b4Sopenharmony_ci *
543d8536b4Sopenharmony_ci * Solution: Decrease the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
553d8536b4Sopenharmony_ci */
563d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_NO_MEMORY     LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x00)
573d8536b4Sopenharmony_ci
583d8536b4Sopenharmony_ci/**
593d8536b4Sopenharmony_ci * @ingroup los_mux
603d8536b4Sopenharmony_ci * Mutex error code: The mutex is not usable.
613d8536b4Sopenharmony_ci *
623d8536b4Sopenharmony_ci * Value: 0x02001d01
633d8536b4Sopenharmony_ci *
643d8536b4Sopenharmony_ci * Solution: Check whether the mutex ID and the mutex state are applicable for the current operation.
653d8536b4Sopenharmony_ci */
663d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_INVALID       LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x01)
673d8536b4Sopenharmony_ci
683d8536b4Sopenharmony_ci/**
693d8536b4Sopenharmony_ci* @ingroup los_mux
703d8536b4Sopenharmony_ci* Mutex error code: Null pointer.
713d8536b4Sopenharmony_ci*
723d8536b4Sopenharmony_ci* Value: 0x02001d02
733d8536b4Sopenharmony_ci*
743d8536b4Sopenharmony_ci* Solution: Check whether the input parameter is usable.
753d8536b4Sopenharmony_ci*/
763d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_PTR_NULL      LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x02)
773d8536b4Sopenharmony_ci
783d8536b4Sopenharmony_ci/**
793d8536b4Sopenharmony_ci* @ingroup los_mux
803d8536b4Sopenharmony_ci* Mutex error code: No mutex is available and the mutex request fails.
813d8536b4Sopenharmony_ci*
823d8536b4Sopenharmony_ci* Value: 0x02001d03
833d8536b4Sopenharmony_ci*
843d8536b4Sopenharmony_ci* Solution: Increase the number of mutexes defined by LOSCFG_BASE_IPC_MUX_LIMIT.
853d8536b4Sopenharmony_ci*/
863d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_ALL_BUSY      LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x03)
873d8536b4Sopenharmony_ci
883d8536b4Sopenharmony_ci/**
893d8536b4Sopenharmony_ci* @ingroup los_mux
903d8536b4Sopenharmony_ci* Mutex error code: The mutex fails to be locked in non-blocking mode because it is locked by another thread.
913d8536b4Sopenharmony_ci*
923d8536b4Sopenharmony_ci* Value: 0x02001d04
933d8536b4Sopenharmony_ci*
943d8536b4Sopenharmony_ci* Solution: Lock the mutex after it is unlocked by the thread that owns it, or set a waiting time.
953d8536b4Sopenharmony_ci*/
963d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_UNAVAILABLE   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x04)
973d8536b4Sopenharmony_ci
983d8536b4Sopenharmony_ci/**
993d8536b4Sopenharmony_ci* @ingroup los_mux
1003d8536b4Sopenharmony_ci* Mutex error code: The mutex is being locked during an interrupt.
1013d8536b4Sopenharmony_ci*
1023d8536b4Sopenharmony_ci* Value: 0x02001d05
1033d8536b4Sopenharmony_ci*
1043d8536b4Sopenharmony_ci* Solution: Check whether the mutex is being locked during an interrupt.
1053d8536b4Sopenharmony_ci*/
1063d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_IN_INTERR   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x05)
1073d8536b4Sopenharmony_ci
1083d8536b4Sopenharmony_ci/**
1093d8536b4Sopenharmony_ci* @ingroup los_mux
1103d8536b4Sopenharmony_ci* Mutex error code: A thread locks a mutex after waiting for the mutex to be unlocked by another thread
1113d8536b4Sopenharmony_ci* when the task scheduling is disabled.
1123d8536b4Sopenharmony_ci*
1133d8536b4Sopenharmony_ci* Value: 0x02001d06
1143d8536b4Sopenharmony_ci*
1153d8536b4Sopenharmony_ci* Solution: Check whether the task scheduling is disabled, or set timeout to 0, which means that the
1163d8536b4Sopenharmony_ci* thread will not wait for the mutex to become available.
1173d8536b4Sopenharmony_ci*/
1183d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_PEND_IN_LOCK  LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x06)
1193d8536b4Sopenharmony_ci
1203d8536b4Sopenharmony_ci/**
1213d8536b4Sopenharmony_ci* @ingroup los_mux
1223d8536b4Sopenharmony_ci* Mutex error code: The mutex locking times out.
1233d8536b4Sopenharmony_ci*
1243d8536b4Sopenharmony_ci* Value: 0x02001d07
1253d8536b4Sopenharmony_ci*
1263d8536b4Sopenharmony_ci* Solution: Increase the waiting time or set the waiting time to LOS_WAIT_FOREVER (forever-blocking mode).
1273d8536b4Sopenharmony_ci*/
1283d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_TIMEOUT       LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x07)
1293d8536b4Sopenharmony_ci
1303d8536b4Sopenharmony_ci/**
1313d8536b4Sopenharmony_ci * @ingroup los_mux
1323d8536b4Sopenharmony_ci *
1333d8536b4Sopenharmony_ci * Value: 0x02001d08
1343d8536b4Sopenharmony_ci * Not in use temporarily.
1353d8536b4Sopenharmony_ci */
1363d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_OVERFLOW      LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x08)
1373d8536b4Sopenharmony_ci
1383d8536b4Sopenharmony_ci/**
1393d8536b4Sopenharmony_ci* @ingroup los_mux
1403d8536b4Sopenharmony_ci* Mutex error code: The mutex to be deleted is being locked.
1413d8536b4Sopenharmony_ci*
1423d8536b4Sopenharmony_ci* Value: 0x02001d09
1433d8536b4Sopenharmony_ci*
1443d8536b4Sopenharmony_ci* Solution: Delete the mutex after it is unlocked.
1453d8536b4Sopenharmony_ci*/
1463d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_PENDED        LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x09)
1473d8536b4Sopenharmony_ci
1483d8536b4Sopenharmony_ci/**
1493d8536b4Sopenharmony_ci * @ingroup los_mux
1503d8536b4Sopenharmony_ci *
1513d8536b4Sopenharmony_ci * Value: 0x02001d0A
1523d8536b4Sopenharmony_ci * Not in use temporarily.
1533d8536b4Sopenharmony_ci */
1543d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_GET_COUNT_ERR LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0A)
1553d8536b4Sopenharmony_ci
1563d8536b4Sopenharmony_ci/**
1573d8536b4Sopenharmony_ci * @ingroup los_mux
1583d8536b4Sopenharmony_ci *
1593d8536b4Sopenharmony_ci * Value: 0x02001d0B
1603d8536b4Sopenharmony_ci * Not in use temporarily.
1613d8536b4Sopenharmony_ci */
1623d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_REG_ERROR     LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0B)
1633d8536b4Sopenharmony_ci
1643d8536b4Sopenharmony_ci/**
1653d8536b4Sopenharmony_ci * @ingroup los_mux
1663d8536b4Sopenharmony_ci *
1673d8536b4Sopenharmony_ci * Mutex error code: LOS_ERRNO_MUX_MAXNUM_ZERO is zero.
1683d8536b4Sopenharmony_ci * Value: 0x02001d0C
1693d8536b4Sopenharmony_ci *
1703d8536b4Sopenharmony_ci * Solution: LOS_ERRNO_MUX_MAXNUM_ZERO should not be zero.
1713d8536b4Sopenharmony_ci */
1723d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_MAXNUM_ZERO   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0C)
1733d8536b4Sopenharmony_ci
1743d8536b4Sopenharmony_ci/**
1753d8536b4Sopenharmony_ci * @ingroup los_mux
1763d8536b4Sopenharmony_ci *
1773d8536b4Sopenharmony_ci * Mutex error code: The API is called in a system-level task, which is forbidden.
1783d8536b4Sopenharmony_ci * Value: 0x02001d0D
1793d8536b4Sopenharmony_ci *
1803d8536b4Sopenharmony_ci * Solution: Do not call the API in system-level tasks.
1813d8536b4Sopenharmony_ci */
1823d8536b4Sopenharmony_ci#define LOS_ERRNO_MUX_PEND_IN_SYSTEM_TASK   LOS_ERRNO_OS_ERROR(LOS_MOD_MUX, 0x0D)
1833d8536b4Sopenharmony_ci
1843d8536b4Sopenharmony_ci/**
1853d8536b4Sopenharmony_ci * @ingroup los_mux
1863d8536b4Sopenharmony_ci * @brief Create a mutex.
1873d8536b4Sopenharmony_ci *
1883d8536b4Sopenharmony_ci * @par Description:
1893d8536b4Sopenharmony_ci * This API is used to create a mutex. A mutex handle is assigned to muxHandle when the mutex is created successfully.
1903d8536b4Sopenharmony_ci * Return LOS_OK on creating successful, return specific error code otherwise.
1913d8536b4Sopenharmony_ci * @attention
1923d8536b4Sopenharmony_ci * <ul>
1933d8536b4Sopenharmony_ci * <li>The total number of mutexes is pre-configured. If there are no available mutexes, the mutex creation fails.</li>
1943d8536b4Sopenharmony_ci * </ul>
1953d8536b4Sopenharmony_ci *
1963d8536b4Sopenharmony_ci * @param muxHandle   [OUT] Handle pointer of the successfully created mutex. The value of handle should be in
1973d8536b4Sopenharmony_ci * [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
1983d8536b4Sopenharmony_ci *
1993d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_PTR_NULL           The muxHandle pointer is NULL.
2003d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_ALL_BUSY           No available mutex.
2013d8536b4Sopenharmony_ci * @retval #LOS_OK                           The mutex is successfully created.
2023d8536b4Sopenharmony_ci * @par Dependency:
2033d8536b4Sopenharmony_ci * <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
2043d8536b4Sopenharmony_ci * @see LOS_MuxDelete
2053d8536b4Sopenharmony_ci */
2063d8536b4Sopenharmony_ciextern UINT32 LOS_MuxCreate(UINT32 *muxHandle);
2073d8536b4Sopenharmony_ci
2083d8536b4Sopenharmony_ci/**
2093d8536b4Sopenharmony_ci * @ingroup los_mux
2103d8536b4Sopenharmony_ci * @brief Delete a mutex.
2113d8536b4Sopenharmony_ci *
2123d8536b4Sopenharmony_ci * @par Description:
2133d8536b4Sopenharmony_ci * This API is used to delete a specified mutex. Return LOS_OK on deleting successfully, return specific error code
2143d8536b4Sopenharmony_ci * otherwise.
2153d8536b4Sopenharmony_ci * @attention
2163d8536b4Sopenharmony_ci * <ul>
2173d8536b4Sopenharmony_ci * <li>The specific mutex should be created firstly.</li>
2183d8536b4Sopenharmony_ci * <li>The mutex can be deleted successfully only if no other tasks pend on it.</li>
2193d8536b4Sopenharmony_ci * </ul>
2203d8536b4Sopenharmony_ci *
2213d8536b4Sopenharmony_ci * @param muxHandle   [IN] Handle of the mutex to be deleted. The value of handle should be in
2223d8536b4Sopenharmony_ci * [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
2233d8536b4Sopenharmony_ci *
2243d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_INVALID            Invalid handle or mutex in use.
2253d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_PENDED             Tasks pended on this mutex.
2263d8536b4Sopenharmony_ci * @retval #LOS_OK                           The mutex is successfully deleted.
2273d8536b4Sopenharmony_ci * @par Dependency:
2283d8536b4Sopenharmony_ci * <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
2293d8536b4Sopenharmony_ci * @see LOS_MuxCreate
2303d8536b4Sopenharmony_ci */
2313d8536b4Sopenharmony_ciextern UINT32 LOS_MuxDelete(UINT32 muxHandle);
2323d8536b4Sopenharmony_ci
2333d8536b4Sopenharmony_ci/**
2343d8536b4Sopenharmony_ci * @ingroup los_mux
2353d8536b4Sopenharmony_ci * @brief Wait to lock a mutex.
2363d8536b4Sopenharmony_ci *
2373d8536b4Sopenharmony_ci * @par Description:
2383d8536b4Sopenharmony_ci * This API is used to wait for a specified period of time to lock a mutex.
2393d8536b4Sopenharmony_ci * @attention
2403d8536b4Sopenharmony_ci * <ul>
2413d8536b4Sopenharmony_ci * <li>The specific mutex should be created firstly.</li>
2423d8536b4Sopenharmony_ci * <li>The function fails if the mutex that is waited on is already locked by another thread when the task scheduling
2433d8536b4Sopenharmony_ci * is disabled.</li>
2443d8536b4Sopenharmony_ci * <li>Do not wait on a mutex during an interrupt.</li>
2453d8536b4Sopenharmony_ci * <li>The priority inheritance protocol is supported. If a higher-priority thread is waiting on a mutex, it changes
2463d8536b4Sopenharmony_ci * the priority of the thread that owns the mutex to avoid priority inversion.</li>
2473d8536b4Sopenharmony_ci * <li>A recursive mutex can be locked more than once by the same thread.</li>
2483d8536b4Sopenharmony_ci * </ul>
2493d8536b4Sopenharmony_ci *
2503d8536b4Sopenharmony_ci * @param muxHandle    [IN] Handle of the mutex to be waited on.  The value of handle should be
2513d8536b4Sopenharmony_ci * in [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
2523d8536b4Sopenharmony_ci * @param timeout      [IN] Waiting time. The value range is [0, LOS_WAIT_FOREVER](unit: Tick).
2533d8536b4Sopenharmony_ci *
2543d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_INVALID            The mutex state (for example, the mutex does not exist or is not in use)
2553d8536b4Sopenharmony_ci *                                           is not applicable for the current operation.
2563d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_UNAVAILABLE        The mutex fails to be locked because it is locked by another thread and
2573d8536b4Sopenharmony_ci * a period of time is not set for waiting for the mutex to become available.
2583d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_IN_INTERR        The mutex is being locked during an interrupt.
2593d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_PEND_IN_LOCK       The mutex is waited on when the task scheduling is disabled.
2603d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_TIMEOUT            The mutex waiting times out.
2613d8536b4Sopenharmony_ci * @retval #LOS_OK                           The mutex is successfully locked.
2623d8536b4Sopenharmony_ci * @par Dependency:
2633d8536b4Sopenharmony_ci * <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
2643d8536b4Sopenharmony_ci * @see LOS_MuxCreate | LOS_MuxPost
2653d8536b4Sopenharmony_ci */
2663d8536b4Sopenharmony_ciextern UINT32 LOS_MuxPend(UINT32 muxHandle, UINT32 timeout);
2673d8536b4Sopenharmony_ci
2683d8536b4Sopenharmony_ci/**
2693d8536b4Sopenharmony_ci * @ingroup los_mux
2703d8536b4Sopenharmony_ci * @brief Release a mutex.
2713d8536b4Sopenharmony_ci *
2723d8536b4Sopenharmony_ci * @par Description:
2733d8536b4Sopenharmony_ci * This API is used to release a specified mutex.
2743d8536b4Sopenharmony_ci * @attention
2753d8536b4Sopenharmony_ci * <ul>
2763d8536b4Sopenharmony_ci * <li>The specific mutex should be created firstly.</li>
2773d8536b4Sopenharmony_ci * <li>Do not release a mutex during an interrupt.</li>
2783d8536b4Sopenharmony_ci * <li>If a recursive mutex is locked for many times, it must be unlocked for the same times to be released.</li>
2793d8536b4Sopenharmony_ci * </ul>
2803d8536b4Sopenharmony_ci *
2813d8536b4Sopenharmony_ci * @param muxHandle    [IN] Handle of the mutex to be released. The value of handle should be in
2823d8536b4Sopenharmony_ci * [0, LOSCFG_BASE_IPC_MUX_LIMIT - 1].
2833d8536b4Sopenharmony_ci *
2843d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_INVALID            The mutex state (for example, the mutex does not exist or is not in use
2853d8536b4Sopenharmony_ci * or owned by other thread) is not applicable for the current operation.
2863d8536b4Sopenharmony_ci * @retval #LOS_ERRNO_MUX_IN_INTERR        The mutex is being released during an interrupt.
2873d8536b4Sopenharmony_ci * @retval #LOS_OK                           The mutex is successfully released.
2883d8536b4Sopenharmony_ci * @par Dependency:
2893d8536b4Sopenharmony_ci * <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
2903d8536b4Sopenharmony_ci * @see LOS_MuxCreate | LOS_MuxPend
2913d8536b4Sopenharmony_ci */
2923d8536b4Sopenharmony_ciextern UINT32 LOS_MuxPost(UINT32 muxHandle);
2933d8536b4Sopenharmony_ci
2943d8536b4Sopenharmony_ci/**
2953d8536b4Sopenharmony_ci * @ingroup los_mux
2963d8536b4Sopenharmony_ci * Mutex object.
2973d8536b4Sopenharmony_ci */
2983d8536b4Sopenharmony_citypedef struct {
2993d8536b4Sopenharmony_ci    UINT8 muxStat;       /**< State OS_MUX_UNUSED,OS_MUX_USED  */
3003d8536b4Sopenharmony_ci    UINT16 muxCount;     /**< Times of locking a mutex */
3013d8536b4Sopenharmony_ci    UINT32 muxID;        /**< Handle ID */
3023d8536b4Sopenharmony_ci    LOS_DL_LIST muxList; /**< Mutex linked list */
3033d8536b4Sopenharmony_ci    LosTaskCB *owner;    /**< The current thread that is locking a mutex */
3043d8536b4Sopenharmony_ci#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
3053d8536b4Sopenharmony_ci    UINTPTR createInfo; /**< Return address of the caller */
3063d8536b4Sopenharmony_ci#endif
3073d8536b4Sopenharmony_ci    UINT16 priority;     /**< Priority of the thread that is locking a mutex */
3083d8536b4Sopenharmony_ci} LosMuxCB;
3093d8536b4Sopenharmony_ci
3103d8536b4Sopenharmony_ci/**
3113d8536b4Sopenharmony_ci * @ingroup los_mux
3123d8536b4Sopenharmony_ci * Mutex state: not in use.
3133d8536b4Sopenharmony_ci */
3143d8536b4Sopenharmony_ci#define OS_MUX_UNUSED 0
3153d8536b4Sopenharmony_ci
3163d8536b4Sopenharmony_ci/**
3173d8536b4Sopenharmony_ci * @ingroup los_mux
3183d8536b4Sopenharmony_ci * Mutex state: in use.
3193d8536b4Sopenharmony_ci */
3203d8536b4Sopenharmony_ci#define OS_MUX_USED   1
3213d8536b4Sopenharmony_ci
3223d8536b4Sopenharmony_ciextern LosMuxCB *g_allMux;
3233d8536b4Sopenharmony_ci
3243d8536b4Sopenharmony_ci/**
3253d8536b4Sopenharmony_ci * @ingroup los_mux
3263d8536b4Sopenharmony_ci * Obtain the pointer to a mutex object of the mutex that has a specified handle.
3273d8536b4Sopenharmony_ci */
3283d8536b4Sopenharmony_ci#define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid))
3293d8536b4Sopenharmony_ci
3303d8536b4Sopenharmony_ci/**
3313d8536b4Sopenharmony_ci * @ingroup los_mux
3323d8536b4Sopenharmony_ci * @brief Initializes the mutex.
3333d8536b4Sopenharmony_ci *
3343d8536b4Sopenharmony_ci * @par Description:
3353d8536b4Sopenharmony_ci * This API is used to initializes the mutex.
3363d8536b4Sopenharmony_ci * @attention
3373d8536b4Sopenharmony_ci * <ul>
3383d8536b4Sopenharmony_ci * <li>None.</li>
3393d8536b4Sopenharmony_ci * </ul>
3403d8536b4Sopenharmony_ci *
3413d8536b4Sopenharmony_ci * @param None.
3423d8536b4Sopenharmony_ci *
3433d8536b4Sopenharmony_ci * @retval UINT32     Initialization result.
3443d8536b4Sopenharmony_ci * @par Dependency:
3453d8536b4Sopenharmony_ci * <ul><li>los_mux.h: the header file that contains the API declaration.</li></ul>
3463d8536b4Sopenharmony_ci * @see LOS_MuxDelete
3473d8536b4Sopenharmony_ci */
3483d8536b4Sopenharmony_ciextern UINT32 OsMuxInit(VOID);
3493d8536b4Sopenharmony_ci
3503d8536b4Sopenharmony_ci/**
3513d8536b4Sopenharmony_ci * @ingroup los_mux
3523d8536b4Sopenharmony_ci * Obtain the pointer to the linked list in the mutex pointed to by a specified pointer.
3533d8536b4Sopenharmony_ci */
3543d8536b4Sopenharmony_ci#define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList)
3553d8536b4Sopenharmony_ci
3563d8536b4Sopenharmony_ci#if (LOSCFG_MUTEX_CREATE_TRACE == 1)
3573d8536b4Sopenharmony_ciSTATIC INLINE VOID OsSetMutexCreateInfo(LosMuxCB *mux, UINTPTR val)
3583d8536b4Sopenharmony_ci{
3593d8536b4Sopenharmony_ci    mux->createInfo = val;
3603d8536b4Sopenharmony_ci}
3613d8536b4Sopenharmony_ci#endif /* LOSCFG_MUTEX_CREATE_TRACE == 1 */
3623d8536b4Sopenharmony_ci
3633d8536b4Sopenharmony_ci#ifdef __cplusplus
3643d8536b4Sopenharmony_ci#if __cplusplus
3653d8536b4Sopenharmony_ci}
3663d8536b4Sopenharmony_ci#endif
3673d8536b4Sopenharmony_ci#endif /* __cplusplus */
3683d8536b4Sopenharmony_ci
3693d8536b4Sopenharmony_ci#endif /* _LOS_MUX_H */
370