mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-08 23:58:31 +08:00
mach: Add __mach_rwlock_*
We cannot use pthread_rwlock for these until we have reimplemented pthread_rwlock with gsync, so fork __libc_rwlock off for now.
This commit is contained in:
+9
-9
@@ -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)
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+4
-4
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user