]>
Commit | Line | Data |
---|---|---|
2b778ceb | 1 | /* Copyright (C) 2002-2021 Free Software Foundation, Inc. |
76a50749 | 2 | This file is part of the GNU C Library. |
9459fe9d | 3 | Ulrich Drepper <drepper@redhat.com>, 2002. |
76a50749 UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library 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 GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
76a50749 | 18 | |
fddfebbd | 19 | #include <semaphore.h> |
a28296e7 | 20 | #include <futex-internal.h> |
76a50749 UD |
21 | #include "pthreadP.h" |
22 | ||
e4f639e4 | 23 | #define SEM_SHM_PREFIX "sem." |
76a50749 | 24 | |
fddfebbd UD |
25 | /* Keeping track of currently used mappings. */ |
26 | struct inuse_sem | |
27 | { | |
28 | dev_t dev; | |
29 | ino_t ino; | |
30 | int refcnt; | |
31 | sem_t *sem; | |
9459fe9d | 32 | char name[]; |
fddfebbd UD |
33 | }; |
34 | ||
76a50749 | 35 | |
fddfebbd UD |
36 | /* The search tree for existing mappings. */ |
37 | extern void *__sem_mappings attribute_hidden; | |
38 | ||
39 | /* Lock to protect the search tree. */ | |
e51deae7 | 40 | extern int __sem_mappings_lock attribute_hidden; |
fddfebbd | 41 | |
76a50749 | 42 | |
fddfebbd UD |
43 | /* Comparison function for search in tree with existing mappings. */ |
44 | extern int __sem_search (const void *a, const void *b) attribute_hidden; | |
45 | ||
a28296e7 ST |
46 | static inline void __new_sem_open_init (struct new_sem *sem, unsigned value) |
47 | { | |
48 | #if __HAVE_64B_ATOMICS | |
49 | sem->data = value; | |
50 | #else | |
51 | sem->value = value << SEM_VALUE_SHIFT; | |
52 | sem->nwaiters = 0; | |
53 | #endif | |
54 | /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */ | |
55 | sem->pad = 0; | |
56 | ||
57 | /* This always is a shared semaphore. */ | |
58 | sem->private = FUTEX_SHARED; | |
59 | } | |
76a50749 UD |
60 | |
61 | /* Prototypes of functions with multiple interfaces. */ | |
62 | extern int __new_sem_init (sem_t *sem, int pshared, unsigned int value); | |
3d2dd6ca | 63 | extern int __old_sem_init (sem_t *sem, int pshared, unsigned int value); |
76a50749 UD |
64 | extern int __new_sem_destroy (sem_t *sem); |
65 | extern int __new_sem_post (sem_t *sem); | |
66 | extern int __new_sem_wait (sem_t *sem); | |
3d2dd6ca | 67 | extern int __old_sem_wait (sem_t *sem); |
76a50749 UD |
68 | extern int __new_sem_trywait (sem_t *sem); |
69 | extern int __new_sem_getvalue (sem_t *sem, int *sval); | |
b8d3e8fb LM |
70 | |
71 | #if __TIMESIZE == 64 | |
72 | # define __sem_clockwait64 __sem_clockwait | |
73 | # define __sem_timedwait64 __sem_timedwait | |
74 | #else | |
75 | extern int | |
76 | __sem_clockwait64 (sem_t *sem, clockid_t clockid, | |
77 | const struct __timespec64 *abstime); | |
78 | libpthread_hidden_proto (__sem_clockwait64) | |
79 | extern int | |
80 | __sem_timedwait64 (sem_t *sem, const struct __timespec64 *abstime); | |
81 | libpthread_hidden_proto (__sem_timedwait64) | |
82 | #endif |