]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
mach: Add __mach_rwlock_*
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 14 Mar 2026 17:59:08 +0000 (17:59 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 14 Mar 2026 17:59:08 +0000 (17:59 +0000)
We cannot use pthread_rwlock for these until we have reimplemented
pthread_rwlock with gsync, so fork __libc_rwlock off for now.

htl/pt-alloc.c
htl/pt-create.c
htl/pt-internal.h
sysdeps/generic/ldsodefs.h
sysdeps/htl/dl-support.c
sysdeps/htl/dl-thread_gscope_wait.c
sysdeps/htl/pt-key-delete.c
sysdeps/mach/hurd/getrandom.c
sysdeps/mach/libc-lock.h

index 257f7250d8d403aa23785f822cd749986ae0f394..53833d3f20d4003b7fcb96afed3a660fec9bd7a3 100644 (file)
@@ -125,7 +125,7 @@ __pthread_alloc (struct __pthread **pthread)
     }
 
 retry:
-  __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
 
   if (GL (dl_pthread_num_threads) < __pthread_max_threads)
     {
@@ -134,7 +134,7 @@ retry:
       new->thread = 1 + GL (dl_pthread_num_threads)++;
       GL (dl_pthread_threads)[new->thread - 1] = NULL;
 
-      __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+      __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
       *pthread = new;
       return 0;
@@ -143,7 +143,7 @@ retry:
   else if (GL (dl_pthread_num_threads) >= PTHREAD_THREADS_MAX)
     {
       /* We have reached the limit on the number of threads per process.  */
-      __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+      __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
       free (new);
       return EAGAIN;
@@ -155,7 +155,7 @@ retry:
      memory allocation, since that's a potentially blocking operation.  */
   max_threads = __pthread_max_threads;
 
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
   /* Allocate a new lookup table that's twice as large.  */
   new_max_threads
@@ -167,13 +167,13 @@ retry:
       return ENOMEM;
     }
 
-  __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
 
   /* Check if nobody else has already enlarged the table.  */
   if (max_threads != __pthread_max_threads)
     {
       /* Yep, they did.  */
-      __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+      __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
       /* Free the newly allocated table and try again to allocate a slot.  */
       free (threads);
@@ -196,7 +196,7 @@ retry:
   new->thread = 1 + GL (dl_pthread_num_threads)++;
   GL (dl_pthread_threads)[new->thread - 1] = NULL;
 
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
   free (old_threads);
 
@@ -211,7 +211,7 @@ __pthread_init_static_tls (struct link_map *map)
 {
   int i;
 
-  __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
   for (i = 0; i < GL (dl_pthread_num_threads); ++i)
     {
       struct __pthread *t = GL (dl_pthread_threads)[i];
@@ -231,6 +231,6 @@ __pthread_init_static_tls (struct link_map *map)
       memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
              '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
     }
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 }
 libc_hidden_def (__pthread_init_static_tls)
index 2a432853722a0e41f6cd6dbffaac265b37ca618e..a66b6ebdcfb3445fe02700f9dd299ffb105c5a57 100644 (file)
@@ -240,9 +240,9 @@ __pthread_create_internal (struct __pthread **thread,
      could use __thread_setid, however, we only lock for reading as no
      other thread should be using this entry (we also assume that the
      store is atomic).  */
-  __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_rdlock (GL (dl_pthread_threads_lock));
   GL (dl_pthread_threads)[pthread->thread - 1] = pthread;
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
   /* At this point it is possible to guess our pthread ID.  We have to
      make sure that all functions taking a pthread_t argument can
index 5a3104830c4939474edb5fdae09e087421fbd880..e662a8d951cf61828c7b034eb0f6760eaf742a48 100644 (file)
@@ -178,16 +178,16 @@ libc_hidden_proto (__pthread_max_threads)
 
 #define __pthread_getid(thread) \
   ({ struct __pthread *__t = NULL;                                           \
-     __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));                    \
+     __mach_rwlock_rdlock (GL (dl_pthread_threads_lock));                    \
      if (thread <= __pthread_max_threads)                                    \
        __t = GL (dl_pthread_threads)[thread - 1];                            \
-     __libc_rwlock_unlock (GL (dl_pthread_threads_lock));                    \
+     __mach_rwlock_unlock (GL (dl_pthread_threads_lock));                    \
      __t; })
 
 #define __pthread_setid(thread, pthread) \
-  __libc_rwlock_wrlock (GL (dl_pthread_threads_lock));                       \
+  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));                       \
   GL (dl_pthread_threads)[thread - 1] = pthread;                             \
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 
 /* Similar to pthread_self, but returns the thread descriptor instead
    of the thread ID.  */
index 76afc5df7decddf0784823b40e3a9c01ad63ebf8..46a7119b3ae175d1d3e26c540dedf10d5eb6c86b 100644 (file)
@@ -478,7 +478,7 @@ struct rtld_global
 
   /* Array of __pthread structures and its lock.  */
   EXTERN struct __pthread **_dl_pthread_threads;
-  __libc_rwlock_define (EXTERN, _dl_pthread_threads_lock)
+  __mach_rwlock_define (EXTERN, _dl_pthread_threads_lock)
 #endif
 #ifdef SHARED
 };
index 0c1edf2bbddbe0dbebe18c54b3bc6ed5db836792..5b07a8f67b2596aff81ecf2d059bfb7c73fb3d35 100644 (file)
@@ -20,4 +20,4 @@
 
 int _dl_pthread_num_threads;
 struct __pthread **_dl_pthread_threads;
-__libc_rwlock_define_initialized (, _dl_pthread_threads_lock)
+__mach_rwlock_define_initialized (, _dl_pthread_threads_lock)
index 095618eac14192dd8528601d01d629dd19c9ede4..d8428d4491838f2cda387fa435756b44d5015eee 100644 (file)
@@ -39,7 +39,7 @@ __thread_gscope_wait (void)
   struct __pthread *t;
   int *gscope_flagp;
 
-  __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_rdlock (GL (dl_pthread_threads_lock));
 
   /* Iterate over the list of threads.  */
   for (i = 0; i < GL (dl_pthread_num_threads); ++i)
@@ -63,5 +63,5 @@ __thread_gscope_wait (void)
       while (*gscope_flagp == THREAD_GSCOPE_FLAG_WAIT);
     }
 
-  __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
 }
index 018a021ee16c136e43ec8cd222797ee1670717da..88f5e33b01801526b9cef74e0077e600d91cfbd6 100644 (file)
@@ -41,7 +41,7 @@ __pthread_key_delete (pthread_key_t key)
       __pthread_key_destructors[key] = PTHREAD_KEY_INVALID;
       __pthread_key_invalid_count++;
 
-      __libc_rwlock_rdlock (GL (dl_pthread_threads_lock));
+      __mach_rwlock_rdlock (GL (dl_pthread_threads_lock));
       for (i = 0; i < GL (dl_pthread_num_threads); ++i)
        {
          struct __pthread *t;
@@ -64,7 +64,7 @@ __pthread_key_delete (pthread_key_t key)
                t->thread_specifics[key] = 0;
            }
        }
-      __libc_rwlock_unlock (GL (dl_pthread_threads_lock));
+      __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
     }
 
   __pthread_mutex_unlock (&__pthread_key_lock);
index 6647a0f778273be8bd1af1f3e5c4a0a9052bad68..a3fde4dc59b38e1ac33650d83525b3671cc14c36 100644 (file)
@@ -20,7 +20,7 @@
 #include <sys/random.h>
 #include <fcntl.h>
 
-__libc_rwlock_define_initialized (static, lock);
+__mach_rwlock_define_initialized (static, lock);
 static file_t random_server, random_server_nonblock,
               urandom_server, urandom_server_nonblock;
 
@@ -75,14 +75,14 @@ __getrandom (void *buffer, size_t length, unsigned int flags)
     return length;
 
 again:
-  __libc_rwlock_rdlock (lock);
+  __mach_rwlock_rdlock (lock);
   server = *cached_server;
   if (MACH_PORT_VALID (server))
     /* Attempt to read some random data using this port.  */
     err = __io_read (server, &data, &nread, -1, length);
   else
     err = MACH_SEND_INVALID_DEST;
-  __libc_rwlock_unlock (lock);
+  __mach_rwlock_unlock (lock);
 
   if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED)
     {
@@ -92,13 +92,13 @@ again:
       /* Slow path: the cached port didn't work, or there was no
          cached port in the first place.  */
 
-      __libc_rwlock_wrlock (lock);
+      __mach_rwlock_wrlock (lock);
       server = *cached_server;
       if (server != oldserver)
         {
           /* Someone else must have refetched the port while we were
              waiting for the lock. */
-          __libc_rwlock_unlock (lock);
+          __mach_rwlock_unlock (lock);
           goto again;
         }
 
@@ -111,7 +111,7 @@ again:
                                       MACH_PORT_RIGHT_SEND, &urefs);
           if (!err && urefs > 0)
             {
-              __libc_rwlock_unlock (lock);
+              __mach_rwlock_unlock (lock);
               goto again;
             }
 
@@ -121,7 +121,7 @@ again:
 
       server = *cached_server = __file_name_lookup (random_source,
                                                     open_flags, 0);
-      __libc_rwlock_unlock (lock);
+      __mach_rwlock_unlock (lock);
       if (!MACH_PORT_VALID (server))
        {
          if (errno == ENOENT)
index 236a24ad807ea292bb25258d64ffb5658f5ddcf5..ddeae544f4b76dddf55b08215a304cf7d766f32a 100644 (file)
@@ -145,7 +145,17 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t;
 #define __rtld_lock_unlock_recursive(NAME) \
   __libc_lock_unlock_recursive (NAME)
 
-/* XXX for now */
+/* XXX for now, waiting for a futex-based pthread_rwlock implementation */
+#define __mach_rwlock_define           __libc_lock_define
+#define __mach_rwlock_define_initialized __libc_lock_define_initialized
+#define __mach_rwlock_init             __libc_lock_init
+#define __mach_rwlock_fini             __libc_lock_fini
+#define __mach_rwlock_rdlock           __libc_lock_lock
+#define __mach_rwlock_wrlock           __libc_lock_lock
+#define __mach_rwlock_tryrdlock                __libc_lock_trylock
+#define __mach_rwlock_trywrlock                __libc_lock_trylock
+#define __mach_rwlock_unlock           __libc_lock_unlock
+
 #define __libc_rwlock_define           __libc_lock_define
 #define __libc_rwlock_define_initialized __libc_lock_define_initialized
 #define __libc_rwlock_init             __libc_lock_init