• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2013-2018. All rights reserved.
3  * Description: semaphore
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_SEM_PRI_H
28 #define _LOS_SEM_PRI_H
29 
30 #include "los_sem.h"
31 
32 #ifdef __cplusplus
33 #if __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 #endif /* __cplusplus */
37 
38 enum LosSemMaxCount {
39     OS_SEM_COUNTING_MAX_COUNT = 0xFFFF, /**< Max count of counting semaphores */
40     OS_SEM_BINARY_MAX_COUNT = 1         /**< Max count of binary semaphores */
41 };
42 
43 /**
44  * @ingroup los_sem
45  * Semaphore control structure.
46  */
47 typedef struct {
48     UINT16 semStat;      /**< Semaphore state */
49     UINT16 semCount;     /**< Number of available semaphores */
50     UINT16 maxSemCount;  /**< Max number of available semaphores */
51     UINT16 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  * Obtain a semaphore ID.
77  *
78  */
79 #define GET_SEM(semid) (((LosSemCB *)g_allSem) + (semid))
80 
81 /**
82  * @ingroup los_sem
83  * @brief Initialize the  Semaphore doubly linked list.
84  *
85  * @par Description:
86  * This API is used to initialize the  Semaphore doubly linked list.
87  * @attention
88  * <ul>
89  * <li>None.</li>
90  * </ul>
91  *
92  * @param None.
93  *
94  * @retval UINT32   Initialization result.
95  * @par Dependency:
96  * <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
97  * @see None.
98  */
99 extern UINT32 OsSemInit(VOID *semArray);
100 
101 /**
102  * @ingroup los_sem
103  * @brief Create Semaphore.
104  *
105  * @par Description:
106  * This API is used to create Semaphore.
107  * @attention
108  * <ul>
109  * <li>None.</li>
110  * </ul>
111  *
112  * @param  count      [IN]Type  #UINT16 Semaphore count.
113  * @param  maxCount   [IN]Type  #UINT16 Max semaphore count.
114  * @param  semHandle  [OUT]Type #UINT32 * Index of semaphore.
115  *
116  * @retval UINT32   Create result.
117  * @par Dependency:
118  * <ul><li>los_sem_pri.h: the header file that contains the API declaration.</li></ul>
119  * @see None.
120  */
121 UINT32 OsSemCreate(UINT16 count, UINT16 maxCount, UINT32 *semHandle);
122 
123 #ifdef __cplusplus
124 #if __cplusplus
125 }
126 #endif /* __cplusplus */
127 #endif /* __cplusplus */
128 
129 #endif /* _LOS_SEM_PRI_H */
130