summaryrefslogtreecommitdiff
path: root/nptl/semaphoreP.h
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-12-13 15:18:16 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-12-16 14:27:24 +0100
commita28296e778ad464d2ba6289446668c3d0dcf1236 (patch)
tree2d3ae8a874d0861f1b5247b02c2cabd390ecf740 /nptl/semaphoreP.h
parent3c1fe20a9f4f6e12a3677ca8a5921ac03976da3b (diff)
downloadglibc-a28296e778ad464d2ba6289446668c3d0dcf1236.tar.gz
pthread: Move semaphore initialization for open to semaphoreP.h
This allows to easily reuse all of the sem_open/sem_close/sem_unlink implementations in the various ports.
Diffstat (limited to 'nptl/semaphoreP.h')
-rw-r--r--nptl/semaphoreP.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h
index f25ba329d7..2f8757e1f0 100644
--- a/nptl/semaphoreP.h
+++ b/nptl/semaphoreP.h
@@ -17,6 +17,7 @@
<https://www.gnu.org/licenses/>. */
#include <semaphore.h>
+#include <futex-internal.h>
#include "pthreadP.h"
#define SEM_SHM_PREFIX "sem."
@@ -42,6 +43,20 @@ extern int __sem_mappings_lock attribute_hidden;
/* Comparison function for search in tree with existing mappings. */
extern int __sem_search (const void *a, const void *b) attribute_hidden;
+static inline void __new_sem_open_init (struct new_sem *sem, unsigned value)
+{
+#if __HAVE_64B_ATOMICS
+ sem->data = value;
+#else
+ sem->value = value << SEM_VALUE_SHIFT;
+ sem->nwaiters = 0;
+#endif
+ /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */
+ sem->pad = 0;
+
+ /* This always is a shared semaphore. */
+ sem->private = FUTEX_SHARED;
+}
/* Prototypes of functions with multiple interfaces. */
extern int __new_sem_init (sem_t *sem, int pshared, unsigned int value);