semaphore.h 4.33 KB
Newer Older
1 2 3 4
/*
 * Module: semaphore.h
 *
 * Purpose:
Pekka Pessi's avatar
Pekka Pessi committed
5 6
 *	Semaphores aren't actually part of the PThreads standard.
 *	They are defined by the POSIX Standard:
7
 *
Pekka Pessi's avatar
Pekka Pessi committed
8
 *		POSIX 1003.1b-1993	(POSIX.1b)
9
 *
Pekka Pessi's avatar
Pekka Pessi committed
10
 * --------------------------------------------------------------------------
11
 *
Pekka Pessi's avatar
Pekka Pessi committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 *      Pthreads-win32 - POSIX Threads Library for Win32
 *      Copyright(C) 1998 John E. Bossom
 *      Copyright(C) 1999,2005 Pthreads-win32 contributors
 * 
 *      Contact Email: rpj@callisto.canberra.edu.au
 * 
 *      The current list of contributors is contained
 *      in the file CONTRIBUTORS included with the source
 *      code distribution. The list can also be seen at the
 *      following World Wide Web location:
 *      http://sources.redhat.com/pthreads-win32/contributors.html
 * 
 *      This library is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU Lesser General Public
 *      License as published by the Free Software Foundation; either
 *      version 2 of the License, or (at your option) any later version.
 * 
 *      This library is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *      Lesser General Public License for more details.
 * 
 *      You should have received a copy of the GNU Lesser General Public
 *      License along with this library in the file COPYING.LIB;
 *      if not, write to the Free Software Foundation, Inc.,
 *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
38 39 40 41
 */
#if !defined( SEMAPHORE_H )
#define SEMAPHORE_H

Pekka Pessi's avatar
Pekka Pessi committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
#undef PTW32_LEVEL

#if defined(_POSIX_SOURCE)
#define PTW32_LEVEL 0
/* Early POSIX */
#endif

#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
#undef PTW32_LEVEL
#define PTW32_LEVEL 1
/* Include 1b, 1c and 1d */
#endif

#if defined(INCLUDE_NP)
#undef PTW32_LEVEL
#define PTW32_LEVEL 2
/* Include Non-Portable extensions */
#endif

#define PTW32_LEVEL_MAX 3

#if !defined(PTW32_LEVEL)
#define PTW32_LEVEL PTW32_LEVEL_MAX
/* Include everything */
#endif

#if __GNUC__ && ! defined (__declspec)
# error Please upgrade your GNU compiler to one that supports __declspec.
#endif

/*
 * When building the DLL code, you should define PTW32_BUILD so that
 * the variables/functions are exported correctly. When using the DLL,
 * do NOT define PTW32_BUILD, and then the variables/functions will
 * be imported correctly.
 */
#ifndef PTW32_STATIC_LIB
#  ifdef PTW32_BUILD
#    define PTW32_DLLPORT __declspec (dllexport)
#  else
#    define PTW32_DLLPORT __declspec (dllimport)
#  endif
#else
#  define PTW32_DLLPORT
#endif

/*
 * This is a duplicate of what is in the autoconf config.h,
 * which is only used when building the pthread-win32 libraries.
 */

#ifndef PTW32_CONFIG_H
#  if defined(WINCE)
#    define NEED_ERRNO
#    define NEED_SEM
#  endif
#  if defined(_UWIN) || defined(__MINGW32__)
#    define HAVE_MODE_T
#  endif
#endif

/*
 *
 */

#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
#include "need_errno.h"
#else
111
#include <errno.h>
Pekka Pessi's avatar
Pekka Pessi committed
112 113
#endif
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
114 115 116 117 118 119

#define _POSIX_SEMAPHORES

#ifdef __cplusplus
extern "C"
{
Pekka Pessi's avatar
Pekka Pessi committed
120
#endif				/* __cplusplus */
121

Pekka Pessi's avatar
Pekka Pessi committed
122
#ifndef HAVE_MODE_T
123 124 125 126
typedef unsigned int mode_t;
#endif


Pekka Pessi's avatar
Pekka Pessi committed
127
typedef struct sem_t_ * sem_t;
128

Pekka Pessi's avatar
Pekka Pessi committed
129 130 131
PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
			    int pshared,
			    unsigned int value);
132

Pekka Pessi's avatar
Pekka Pessi committed
133
PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
134

Pekka Pessi's avatar
Pekka Pessi committed
135
PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
136

Pekka Pessi's avatar
Pekka Pessi committed
137
PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
138

Pekka Pessi's avatar
Pekka Pessi committed
139 140
PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
				 const struct timespec * abstime);
141

Pekka Pessi's avatar
Pekka Pessi committed
142
PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
143

Pekka Pessi's avatar
Pekka Pessi committed
144 145
PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
				     int count);
146

Pekka Pessi's avatar
Pekka Pessi committed
147 148 149 150 151 152 153 154 155 156 157
PTW32_DLLPORT int __cdecl sem_open (const char * name,
			    int oflag,
			    mode_t mode,
			    unsigned int value);

PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);

PTW32_DLLPORT int __cdecl sem_unlink (const char * name);

PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
				int * sval);
158 159

#ifdef __cplusplus
Pekka Pessi's avatar
Pekka Pessi committed
160 161 162 163 164
}				/* End of extern "C" */
#endif				/* __cplusplus */

#undef PTW32_LEVEL
#undef PTW32_LEVEL_MAX
165

Pekka Pessi's avatar
Pekka Pessi committed
166
#endif				/* !SEMAPHORE_H */