git-sem-open-init
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Tue, 27 May 2025 10:40:04 +0000 (11:40 +0100)
committerSean Whitton <spwhitton@spwhitton.name>
Tue, 27 May 2025 10:40:04 +0000 (11:40 +0100)
Submitted for 2.33

commit e453b54b02204e0bc4a36a865ecc0c82058f4f9d
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Dec 13 15:18:16 2020 +0000

    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.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name git-sem-open-init.diff

nptl/sem_open.c
nptl/semaphoreP.h
sysdeps/nptl/futex-internal.h

index b022cbfd9a4f69eb9f1231feae9ee35af5a822dc..eca57e0979a1a9818c33e244f01b46c042e98bb8 100644 (file)
@@ -211,17 +211,7 @@ sem_open (const char *name, int oflag, ...)
        struct new_sem newsem;
       } sem;
 
-#if __HAVE_64B_ATOMICS
-      sem.newsem.data = value;
-#else
-      sem.newsem.value = value << SEM_VALUE_SHIFT;
-      sem.newsem.nwaiters = 0;
-#endif
-      /* pad is used as a mutex on pre-v9 sparc and ignored otherwise.  */
-      sem.newsem.pad = 0;
-
-      /* This always is a shared semaphore.  */
-      sem.newsem.private = FUTEX_SHARED;
+      __new_sem_open_init (&sem.newsem, value);
 
       /* Initialize the remaining bytes as well.  */
       memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0',
index e7e1c9763f724fae95bad851c4a9e58ff08f771e..c202ce2a6ee86f598815a5b87ad9a311a0dcd272 100644 (file)
@@ -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);
index d622122ddcef4db9155a7c6abbdd8970d457ee94..00338d6480301a86e4d19551309195a2fa3fe312 100644 (file)
 #include <sys/time.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <lowlevellock-futex.h>
 #include <libc-diag.h>
+#include <errno.h>
+#include <pthread.h>
 
 /* This file defines futex operations used internally in glibc.  A futex
    consists of the so-called futex word in userspace, which is of type