• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LOS_SEM_PRI_H
33 #define _LOS_SEM_PRI_H
34 
35 #include "los_sem.h"
36 
37 #ifdef __cplusplus
38 #if __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 #endif /* __cplusplus */
42 
43 /**
44  * @ingroup los_sem
45  * Semaphore control structure.
46  */
47 typedef struct {
48     UINT8 semStat; /**< Semaphore state */
49     UINT16 semCount; /**< Number of available semaphores */
50     UINT16 maxSemCount;  /**< Max number of available semaphores */
51     UINT32 semID; /**< Semaphore control structure ID */
52     LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore */
53 } LosSemCB;
54 
55 /**
56  * @ingroup los_sem
57  * The semaphore is not in use.
58  *
59  */
60 #define OS_SEM_UNUSED        0
61 /**
62  * @ingroup los_sem
63  * The semaphore is used.
64  *
65  */
66 #define OS_SEM_USED          1
67 /**
68  * @ingroup los_sem
69  * Obtain the head node in a semaphore doubly linked list.
70  *
71  */
72 #define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
73 extern LosSemCB *g_allSem;
74 /**
75  * @ingroup los_sem
76  * COUNT | INDEX  split bit
77  */
78 #define SEM_SPLIT_BIT        16
79 /**
80  * @ingroup los_sem
81  * Set the semaphore id
82  */
83 #define SET_SEM_ID(count, semID)    (((count) << SEM_SPLIT_BIT) | (semID))
84 
85 /**
86  * @ingroup los_sem
87  * get the semaphore index
88  */
89 #define GET_SEM_INDEX(semID)        ((semID) & ((1U << SEM_SPLIT_BIT) - 1))
90 
91 /**
92  * @ingroup los_sem
93  * get the semaphore count
94  */
95 #define GET_SEM_COUNT(semID)        ((semID) >> SEM_SPLIT_BIT)
96 
97 /**
98  * @ingroup los_sem
99  * Obtain a semaphore ID.
100  *
101  */
102 #define GET_SEM(semID)              (((LosSemCB *)g_allSem) + GET_SEM_INDEX(semID))
103 
104 /**
105  * @ingroup los_sem
106  * Maximum value of task information.
107  *
108  */
109 #define OS_MAX_PENDTASK_INFO 4
110 
111 extern UINT32 OsSemInit(VOID);
112 extern UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched);
113 
114 #ifdef __cplusplus
115 #if __cplusplus
116 }
117 #endif /* __cplusplus */
118 #endif /* __cplusplus */
119 
120 #endif /* _LOS_SEM_PRI_H */
121