+2003-05-01 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/i386/tls.h: Define THREAD_ID.
+ * sysdeps/ia64/tls.h: Likewise.
+ * sysdeps/powerpc/tls.h: Likewise.
+ * sysdeps/s390/tls.h: Likewise.
+ * sysdeps/sh/tls.h: Likewise.
+ * sysdeps/x86_64/tls.h: Likewise.
+ * pthread_mutex_lock.c: Use THREAD_ID instead of THREAD_SELF to
+ record ownership.
+ * pthread_mutex_timedlock.c: Likewise.
+ * pthread_mutex_trylock.c: Likewise.
+ * pthread_mutex_unlock.c: Likewise.
+ * pthread_rwlock_trywrlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlocklock_rdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedrdlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_timedwrlock.c: Likewise.
+ * sysdeps/pthread/pthread_rwlock_wrlock.c: Likewise.
+
+ * sysdeps/pthread/createthread.c (create_thread): Use CLONE_SYSVSEM
+ flag.
+
2003-04-29 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/x86_64/bits/pthreadtypes.h
__pthread_mutex_lock (mutex)
pthread_mutex_t *mutex;
{
- struct pthread *pd = THREAD_SELF;
+ struct pthread *id = THREAD_ID;
switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
{
/* Recursive mutex. */
case PTHREAD_MUTEX_RECURSIVE_NP:
/* Check whether we already hold the mutex. */
- if (mutex->__data.__owner == pd)
+ if (mutex->__data.__owner == id)
{
/* Just bump the counter. */
if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
lll_mutex_lock (mutex->__data.__lock);
/* Record the ownership. */
- mutex->__data.__owner = pd;
+ mutex->__data.__owner = id;
mutex->__data.__count = 1;
}
break;
/* Error checking mutex. */
case PTHREAD_MUTEX_ERRORCHECK_NP:
/* Check whether we already hold the mutex. */
- if (mutex->__data.__owner == pd)
+ if (mutex->__data.__owner == id)
return EDEADLK;
/* FALLTHROUGH */
/* Normal mutex. */
lll_mutex_lock (mutex->__data.__lock);
/* Record the ownership. */
- mutex->__data.__owner = pd;
+ mutex->__data.__owner = id;
break;
}
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
pthread_mutex_t *mutex;
const struct timespec *abstime;
{
- struct pthread *pd = THREAD_SELF;
+ struct pthread *id = THREAD_ID;
int result = 0;
/* We must not check ABSTIME here. If the thread does not block
/* Recursive mutex. */
case PTHREAD_MUTEX_RECURSIVE_NP:
/* Check whether we already hold the mutex. */
- if (mutex->__data.__owner == pd)
+ if (mutex->__data.__owner == id)
{
/* Just bump the counter. */
if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
/* Error checking mutex. */
case PTHREAD_MUTEX_ERRORCHECK_NP:
/* Check whether we already hold the mutex. */
- if (mutex->__data.__owner == pd)
+ if (mutex->__data.__owner == id)
return EDEADLK;
/* FALLTHROUGH */
if (result == 0)
/* Record the ownership. */
- mutex->__data.__owner = pd;
+ mutex->__data.__owner = id;
out:
return result;
__pthread_mutex_trylock (mutex)
pthread_mutex_t *mutex;
{
- struct pthread *pd = THREAD_SELF;
+ struct pthread *id = THREAD_ID;
switch (__builtin_expect (mutex->__data.__kind, PTHREAD_MUTEX_TIMED_NP))
{
/* Recursive mutex. */
case PTHREAD_MUTEX_RECURSIVE_NP:
/* Check whether we already hold the mutex. */
- if (mutex->__data.__owner == pd)
+ if (mutex->__data.__owner == id)
{
/* Just bump the counter. */
if (__builtin_expect (mutex->__data.__count + 1 == 0, 0))
if (lll_mutex_trylock (mutex->__data.__lock) == 0)
{
/* Record the ownership. */
- mutex->__data.__owner = pd;
+ mutex->__data.__owner = id;
mutex->__data.__count = 1;
return 0;
}
if (lll_mutex_trylock (mutex->__data.__lock) == 0)
{
/* Record the ownership. */
- mutex->__data.__owner = pd;
+ mutex->__data.__owner = id;
return 0;
}
{
case PTHREAD_MUTEX_RECURSIVE_NP:
/* Recursive mutex. */
- if (mutex->__data.__owner != THREAD_SELF)
+ if (mutex->__data.__owner != THREAD_ID)
return EPERM;
if (--mutex->__data.__count != 0)
/* We still hold the mutex. */
return 0;
-
- mutex->__data.__owner = NULL;
break;
case PTHREAD_MUTEX_ERRORCHECK_NP:
/* Error checking mutex. */
- if (mutex->__data.__owner != THREAD_SELF
+ if (mutex->__data.__owner != THREAD_ID
|| ! lll_mutex_islocked (mutex->__data.__lock))
return EPERM;
-
- mutex->__data.__owner = NULL;
break;
default:
break;
}
+ /* Always reset the owner field. */
+ mutex->__data.__owner = NULL;
+
/* Unlock. */
lll_mutex_unlock (mutex->__data.__lock);
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
{
- rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+ rwlock->__data.__writer = (pthread_t) THREAD_ID;
result = 0;
}
: "i" (offsetof (struct pthread, header.self))); \
__self;})
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary. It is fine here. */
+# define THREAD_ID THREAD_SELF
+
/* Read member of the thread descriptor directly. */
# define THREAD_GETMEM(descr, member) \
/* Return the thread descriptor for the current thread. */
# define THREAD_SELF (__thread_self - 1)
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary as in this case. */
+# define THREAD_ID __thread_self
+
/* Access to data in the thread descriptor is easy. */
#define THREAD_GETMEM(descr, member) \
descr->member
((struct pthread *) (__thread_register \
- TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary as in this case. */
+# define THREAD_ID __thread_register
+
/* Read member of the thread descriptor directly. */
# define THREAD_GETMEM(descr, member) ((void)(descr), (THREAD_SELF)->member)
if (ARCH_CLONE (start_thread_debug, STACK_VARIABLES_ARGS,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL |
CLONE_SETTLS | CLONE_PARENT_SETTID |
- CLONE_CHILD_CLEARTID | CLONE_DETACHED | 0,
- pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
+ CLONE_CHILD_CLEARTID | CLONE_DETACHED |
+ CLONE_SYSVSEM | 0, pd, &pd->tid, TLS_VALUE,
+ &pd->tid) == -1)
/* Failed. */
return errno;
if (ARCH_CLONE (start_thread, STACK_VARIABLES_ARGS,
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL |
CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID |
- CLONE_DETACHED | 0, pd, &pd->tid, TLS_VALUE, &pd->tid) == -1)
+ CLONE_DETACHED | CLONE_SYSVSEM | 0, pd, &pd->tid, TLS_VALUE,
+ &pd->tid) == -1)
/* Failed. */
return errno;
a deadlock situation we recognize and report. */
if (rwlock->__data.__writer != 0
&& __builtin_expect (rwlock->__data.__writer
- == (pthread_t) THREAD_SELF, 0))
+ == (pthread_t) THREAD_ID, 0))
{
result = EDEADLK;
break;
a deadlock situation we recognize and report. */
if (rwlock->__data.__writer != 0
&& __builtin_expect (rwlock->__data.__writer
- == (pthread_t) THREAD_SELF, 0))
+ == (pthread_t) THREAD_ID, 0))
{
result = EDEADLK;
break;
if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
{
/* Mark self as writer. */
- rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+ rwlock->__data.__writer = (pthread_t) THREAD_ID;
break;
}
a deadlock situation we recognize and report. */
if (rwlock->__data.__writer != 0
&& __builtin_expect (rwlock->__data.__writer
- == (pthread_t) THREAD_SELF, 0))
+ == (pthread_t) THREAD_ID, 0))
{
result = EDEADLK;
break;
if (rwlock->__data.__writer == 0 && rwlock->__data.__nr_readers == 0)
{
/* Mark self as writer. */
- rwlock->__data.__writer = (pthread_t) THREAD_SELF;
+ rwlock->__data.__writer = (pthread_t) THREAD_ID;
break;
}
a deadlock situation we recognize and report. */
if (rwlock->__data.__writer != 0
&& __builtin_expect (rwlock->__data.__writer
- == (pthread_t) THREAD_SELF, 0))
+ == (pthread_t) THREAD_ID, 0))
{
result = EDEADLK;
break;
/* Return the thread descriptor for the current thread. */
# define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ())
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary. It is fine here. */
+# define THREAD_ID THREAD_SELF
+
/* Access to data in the thread descriptor is easy. */
#define THREAD_GETMEM(descr, member) \
descr->member
__asm ("stc gbr,%0" : "=r" (__self)); \
__self - 1;})
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary as in this case. */
+# define THREAD_ID \
+ ({ struct pthread *__self; \
+ __asm ("stc gbr,%0" : "=r" (__self)); \
+ __self;})
+
/* Read member of the thread descriptor directly. */
# define THREAD_GETMEM(descr, member) (descr->member)
: "i" (offsetof (struct pthread, header.self))); \
__self;})
+/* Identifier for the current thread. THREAD_SELF is usable but
+ sometimes more expensive than necessary. It is fine here. */
+# define THREAD_ID THREAD_SELF
+
/* Read member of the thread descriptor directly. */
# define THREAD_GETMEM(descr, member) \