1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2018. All rights reserved. 3 * Description: mutex 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 9 * of conditions and the following disclaimer in the documentation and/or other materials 10 * provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 12 * to endorse or promote products derived from this software without specific prior written 13 * permission. 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * --------------------------------------------------------------------------- */ 26 27 #ifndef _LOS_MUX_PRI_H 28 #define _LOS_MUX_PRI_H 29 30 #include "los_task_pri.h" 31 #include "los_mux.h" 32 33 #ifdef __cplusplus 34 #if __cplusplus 35 extern "C" { 36 #endif /* __cplusplus */ 37 #endif /* __cplusplus */ 38 39 /** 40 * @ingroup los_mux 41 * Mutex object. 42 */ 43 typedef struct { 44 UINT8 muxStat; /**< State OS_MUX_UNUSED,OS_MUX_USED */ 45 UINT16 muxCount; /**< Times of locking a mutex */ 46 UINT32 muxID; /**< Handle ID */ 47 LOS_DL_LIST muxList; /**< Mutex linked list */ 48 LosTaskCB *owner; /**< The current thread that is locking a mutex */ 49 UINT16 priority; /**< Priority of the thread that is locking a mutex */ 50 } LosMuxCB; 51 52 /** 53 * @ingroup los_mux 54 * Mutex state: not in use. 55 */ 56 #define OS_MUX_UNUSED 0 57 58 /** 59 * @ingroup los_mux 60 * Mutex state: in use. 61 */ 62 #define OS_MUX_USED 1 63 64 extern LosMuxCB *g_allMux; 65 66 /** 67 * @ingroup los_mux 68 * Obtain the pointer to a mutex object of the mutex that has a specified handle. 69 */ 70 #define GET_MUX(muxid) (((LosMuxCB *)g_allMux) + (muxid)) 71 72 /** 73 * @ingroup los_mux 74 * @brief Initializes the mutex. 75 * 76 * @par Description: 77 * This API is used to initializes the mutex. 78 * @attention 79 * <ul> 80 * <li>None.</li> 81 * </ul> 82 * 83 * @param None. 84 * 85 * @retval UINT32 Initialization result. 86 * @par Dependency: 87 * <ul><li>los_mux_pri.h: the header file that contains the API declaration.</li></ul> 88 * @see LOS_MuxDelete 89 */ 90 extern UINT32 OsMuxInit(VOID *muxArray); 91 92 /** 93 * @ingroup los_mux 94 * Obtain the pointer to the linked list in the mutex pointed to by a specified pointer. 95 */ 96 #define GET_MUX_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosMuxCB, muxList) 97 98 #ifdef __cplusplus 99 #if __cplusplus 100 } 101 #endif /* __cplusplus */ 102 #endif /* __cplusplus */ 103 104 #endif /* _LOS_MUX_PRI_H */ 105