]> git.ipfire.org Git - thirdparty/glibc.git/blame - linuxthreads/semaphore.h
Update.
[thirdparty/glibc.git] / linuxthreads / semaphore.h
CommitLineData
5afdca00
UD
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. */
14
15#ifndef _SEMAPHORE_H
16#define _SEMAPHORE_H 1
17
18#include <features.h>
8325d82c 19#include <sys/types.h>
8e605e78
UD
20#ifdef __USE_XOPEN2K
21# define __need_timespec
22# include <time.h>
23#endif
5afdca00 24
f8afba91
UD
25#ifndef _PTHREAD_DESCR_DEFINED
26/* Thread descriptors. Needed for `sem_t' definition. */
27typedef struct _pthread_descr_struct *_pthread_descr;
28# define _PTHREAD_DESCR_DEFINED
29#endif
5afdca00 30
f8afba91
UD
31/* System specific semaphore definition. */
32typedef struct
33{
34 struct
35 {
36 long int status;
37 int spinlock;
38 } __sem_lock;
39 int __sem_value;
40 _pthread_descr __sem_waiting;
3387a425 41} sem_t;
5afdca00 42
f8afba91
UD
43
44
45/* Value returned if `sem_open' failed. */
93a19c64 46#define SEM_FAILED ((sem_t *) 0)
f8afba91
UD
47
48/* Maximum value the semaphore can have. */
49#define SEM_VALUE_MAX ((int) ((~0u) >> 1))
50
51
5afdca00
UD
52__BEGIN_DECLS
53
f8afba91
UD
54/* Initialize semaphore object SEM to VALUE. If PSHARED then share it
55 with other processes. */
a9b5d2ee 56extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value) __THROW;
f8afba91
UD
57
58/* Free resources associated with semaphore object SEM. */
a9b5d2ee 59extern int sem_destroy (sem_t *__sem) __THROW;
f8afba91
UD
60
61/* Open a named semaphore NAME with open flaot OFLAG. */
a9b5d2ee 62extern sem_t *sem_open (__const char *__name, int __oflag, ...) __THROW;
f8afba91
UD
63
64/* Close descriptor for named semaphore SEM. */
a9b5d2ee 65extern int sem_close (sem_t *__sem) __THROW;
f8afba91
UD
66
67/* Remove named semaphore NAME. */
a9b5d2ee 68extern int sem_unlink (__const char *__name) __THROW;
f8afba91
UD
69
70/* Wait for SEM being posted. */
a9b5d2ee 71extern int sem_wait (sem_t *__sem) __THROW;
f8afba91 72
8e605e78
UD
73#ifdef __USE_XOPEN2K
74/* Similar to `sem_wait' but wait only until ABSTIME. */
98cbe360
UD
75extern int sem_timedwait (sem_t *__restrict __sem,
76 __const struct timespec *__restrict __abstime)
8e605e78
UD
77 __THROW;
78#endif
79
f8afba91 80/* Test whether SEM is posted. */
a9b5d2ee 81extern int sem_trywait (sem_t *__sem) __THROW;
f8afba91
UD
82
83/* Post SEM. */
a9b5d2ee 84extern int sem_post (sem_t *__sem) __THROW;
f8afba91
UD
85
86/* Get current value of SEM and store it in *SVAL. */
98cbe360
UD
87extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
88 __THROW;
5afdca00
UD
89
90__END_DECLS
91
92#endif /* semaphore.h */