• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
3  * Description: LiteOS compat headfile for nuttx semaphore
4  * Author: Huawei LiteOS Team
5  * Create: 2022-07-15
6  * Redistribution and use in source and binary forms, with or without modification,
7  * are permitted provided that the following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  * conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14  * to endorse or promote products derived from this software without specific prior written
15  * permission.
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * --------------------------------------------------------------------------- */
28 
29 #ifndef __INCLUDE_NUTTX_SEMAPHORE_H
30 #define __INCLUDE_NUTTX_SEMAPHORE_H
31 
32 /****************************************************************************
33  * Included Files
34  ****************************************************************************/
35 
36 /* Avoid including this header file. */
37 #include <semaphore.h>
38 
39 #undef EXTERN
40 #if defined(__cplusplus)
41 #define EXTERN extern "C"
42 extern "C"
43 {
44 #else
45 #define EXTERN extern
46 #endif
47 
48 /****************************************************************************
49  * Public Function Prototypes
50  ****************************************************************************/
51 
52 /* Compatible with the NuttX internal OS interface:
53  * It follows the NuttX internal error return policy: Zero (OK) is
54  * returned on success. A negated errno value is returned on failure.
55  */
56 int nxsem_init(sem_t *sem, int pshared, unsigned int value);
57 int nxsem_post(sem_t *sem);
58 int nxsem_wait(sem_t *sem);
59 int nxsem_destroy(sem_t *sem);
60 
61 #define nxsem_wait_uninterruptible nxsem_wait
62 
63 /* LiteOS does not support static semaphore.
64  * Therefore, this parameter needs to be set to null.
65  */
66 
67 #define SEM_INITIALIZER(sem)  {}
68 
69 #undef EXTERN
70 #if defined(__cplusplus)
71 }
72 #endif
73 
74 #endif /* __INCLUDE_NUTTX_SEMAPHORE_H */
75