xref: /OK3568_Linux_fs/external/mpp/osal/windows/pthread/inc/semaphore.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Module: semaphore.h
3  *
4  * Purpose:
5  *	Semaphores aren't actually part of the PThreads standard.
6  *	They are defined by the POSIX Standard:
7  *
8  *		POSIX 1003.1b-1993	(POSIX.1b)
9  *
10  * --------------------------------------------------------------------------
11  *
12  *      Pthreads-win32 - POSIX Threads Library for Win32
13  *      Copyright(C) 1998 John E. Bossom
14  *      Copyright(C) 1999,2005 Pthreads-win32 contributors
15  *
16  *      Contact Email: rpj@callisto.canberra.edu.au
17  *
18  *      The current list of contributors is contained
19  *      in the file CONTRIBUTORS included with the source
20  *      code distribution. The list can also be seen at the
21  *      following World Wide Web location:
22  *      http://sources.redhat.com/pthreads-win32/contributors.html
23  *
24  *      This library is free software; you can redistribute it and/or
25  *      modify it under the terms of the GNU Lesser General Public
26  *      License as published by the Free Software Foundation; either
27  *      version 2 of the License, or (at your option) any later version.
28  *
29  *      This library is distributed in the hope that it will be useful,
30  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
31  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32  *      Lesser General Public License for more details.
33  *
34  *      You should have received a copy of the GNU Lesser General Public
35  *      License along with this library in the file COPYING.LIB;
36  *      if not, write to the Free Software Foundation, Inc.,
37  *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
38  */
39 #if !defined( SEMAPHORE_H )
40 #define SEMAPHORE_H
41 
42 #undef PTW32_SEMAPHORE_LEVEL
43 
44 #if defined(_POSIX_SOURCE)
45 #define PTW32_SEMAPHORE_LEVEL 0
46 /* Early POSIX */
47 #endif
48 
49 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
50 #undef PTW32_SEMAPHORE_LEVEL
51 #define PTW32_SEMAPHORE_LEVEL 1
52 /* Include 1b, 1c and 1d */
53 #endif
54 
55 #if defined(INCLUDE_NP)
56 #undef PTW32_SEMAPHORE_LEVEL
57 #define PTW32_SEMAPHORE_LEVEL 2
58 /* Include Non-Portable extensions */
59 #endif
60 
61 #define PTW32_SEMAPHORE_LEVEL_MAX 3
62 
63 #if !defined(PTW32_SEMAPHORE_LEVEL)
64 #define PTW32_SEMAPHORE_LEVEL PTW32_SEMAPHORE_LEVEL_MAX
65 /* Include everything */
66 #endif
67 
68 #if defined(__GNUC__) && ! defined (__declspec)
69 # error Please upgrade your GNU compiler to one that supports __declspec.
70 #endif
71 
72 /*
73  * When building the library, you should define PTW32_BUILD so that
74  * the variables/functions are exported correctly. When using the library,
75  * do NOT define PTW32_BUILD, and then the variables/functions will
76  * be imported correctly.
77  */
78 #if !defined(PTW32_STATIC_LIB)
79 #  if defined(PTW32_BUILD)
80 #    define PTW32_DLLPORT __declspec (dllexport)
81 #  else
82 #    define PTW32_DLLPORT __declspec (dllimport)
83 #  endif
84 #else
85 #  define PTW32_DLLPORT
86 #endif
87 
88 /*
89  * This is a duplicate of what is in the autoconf config.h,
90  * which is only used when building the pthread-win32 libraries.
91  */
92 
93 #if !defined(PTW32_CONFIG_H)
94 #  if defined(WINCE)
95 #    define NEED_ERRNO
96 #    define NEED_SEM
97 #  endif
98 #  if defined(__MINGW64__)
99 #    define HAVE_STRUCT_TIMESPEC
100 #    define HAVE_MODE_T
101 #  elif defined(_UWIN) || defined(__MINGW32__)
102 #    define HAVE_MODE_T
103 #  endif
104 #endif
105 
106 /*
107  *
108  */
109 
110 #if PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX
111 #if defined(NEED_ERRNO)
112 #include "need_errno.h"
113 #else
114 #include <errno.h>
115 #endif
116 #endif /* PTW32_SEMAPHORE_LEVEL >= PTW32_SEMAPHORE_LEVEL_MAX */
117 
118 #define _POSIX_SEMAPHORES
119 
120 #if defined(__cplusplus)
121 extern "C"
122 {
123 #endif				/* __cplusplus */
124 
125 #if !defined(HAVE_MODE_T)
126 typedef unsigned int mode_t;
127 #endif
128 
129 
130 typedef struct sem_t_ * sem_t;
131 
132 PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
133 			    int pshared,
134 			    unsigned int value);
135 
136 PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
137 
138 PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
139 
140 PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
141 
142 PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
143 				 const struct timespec * abstime);
144 
145 PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
146 
147 PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
148 				     int count);
149 
150 PTW32_DLLPORT int __cdecl sem_open (const char * name,
151 			    int oflag,
152 			    mode_t mode,
153 			    unsigned int value);
154 
155 PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
156 
157 PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
158 
159 PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
160 				int * sval);
161 
162 #if defined(__cplusplus)
163 }				/* End of extern "C" */
164 #endif				/* __cplusplus */
165 
166 #undef PTW32_SEMAPHORE_LEVEL
167 #undef PTW32_SEMAPHORE_LEVEL_MAX
168 
169 #endif				/* !SEMAPHORE_H */
170