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