Update.
[glibc.git] / linuxthreads / semaphore.h
bloba3cc422377ad818eb2b1bf670c95eef29ef0ab5e
1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
4 /* */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU Library General Public License for more details. */
15 #ifndef _SEMAPHORE_H
16 #define _SEMAPHORE_H 1
18 #include <features.h>
19 #include <sys/types.h>
21 #ifndef _PTHREAD_DESCR_DEFINED
22 /* Thread descriptors. Needed for `sem_t' definition. */
23 typedef struct _pthread_descr_struct *_pthread_descr;
24 # define _PTHREAD_DESCR_DEFINED
25 #endif
27 /* System specific semaphore definition. */
28 typedef struct
30 struct
32 long int status;
33 int spinlock;
34 } __sem_lock;
35 int __sem_value;
36 _pthread_descr __sem_waiting;
37 } sem_t;
41 /* Value returned if `sem_open' failed. */
42 #define SEM_FAILED ((sem_t *) NULL)
44 /* Maximum value the semaphore can have. */
45 #define SEM_VALUE_MAX ((int) ((~0u) >> 1))
48 __BEGIN_DECLS
50 /* Initialize semaphore object SEM to VALUE. If PSHARED then share it
51 with other processes. */
52 extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value) __THROW;
54 /* Free resources associated with semaphore object SEM. */
55 extern int sem_destroy (sem_t *__sem) __THROW;
57 /* Open a named semaphore NAME with open flaot OFLAG. */
58 extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
60 /* Close descriptor for named semaphore SEM. */
61 extern int sem_close (sem_t *__sem) __THROW;
63 /* Remove named semaphore NAME. */
64 extern int sem_unlink (__const char *__name) __THROW;
66 /* Wait for SEM being posted. */
67 extern int sem_wait (sem_t *__sem) __THROW;
69 /* Test whether SEM is posted. */
70 extern int sem_trywait (sem_t *__sem) __THROW;
72 /* Post SEM. */
73 extern int sem_post (sem_t *__sem) __THROW;
75 /* Get current value of SEM and store it in *SVAL. */
76 extern int sem_getvalue (sem_t *__sem, int *__sval) __THROW;
78 __END_DECLS
80 #endif /* semaphore.h */