diff options
author | Neal H. Walfield <neal@gnu.org> | 2008-01-01 17:42:41 +0000 |
---|---|---|
committer | Thomas Schwinge <tschwinge@gnu.org> | 2009-04-07 23:11:53 +0200 |
commit | 00905beb9fabe556ae905b5eaa14e8c76dff7d79 (patch) | |
tree | 1f1f2349dd65fe62a938f9bf9b725131b3875d43 /sysdeps/generic/pt-mutex-timedlock.c | |
parent | 580da795e84996d81b3db9ef1878d8569a4b9530 (diff) |
2008-01-01 Neal H. Walfield <neal@gnu.org>
* sysdeps/generic/pt-mutex-timedlock.c
(__pthread_mutex_timedlock_internal): Add additional asserts.
[! NDEBUG]: Keep MUTEX->OWNER up to date.
* sysdeps/generic/pt-mutex-trylock.c (__pthread_mutex_trylock):
Add additional asserts.
[! NDEBUG]: Keep MUTEX->OWNER up to date.
* sysdeps/generic/pt-mutex-unlock.c (__pthread_mutex_unlock): Add
additional asserts.
[! NDEBUG]: Keep MUTEX->OWNER up to date.
Diffstat (limited to 'sysdeps/generic/pt-mutex-timedlock.c')
-rw-r--r-- | sysdeps/generic/pt-mutex-timedlock.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/sysdeps/generic/pt-mutex-timedlock.c b/sysdeps/generic/pt-mutex-timedlock.c index 5e222bd..6db30c5 100644 --- a/sysdeps/generic/pt-mutex-timedlock.c +++ b/sysdeps/generic/pt-mutex-timedlock.c @@ -1,5 +1,5 @@ /* Lock a mutex with a timeout. Generic version. - Copyright (C) 2000, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2005, 2008 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -36,6 +36,18 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex, if (__pthread_spin_trylock (&mutex->__held) == 0) /* Successfully acquired the lock. */ { +#ifndef NDEBUG + self = _pthread_self (); + if (self) + /* The main thread may take a lock before the library is fully + initialized, in particular, before the main thread has a + TCB. */ + { + assert (! mutex->owner); + mutex->owner = _pthread_self (); + } +#endif + if (mutex->attr) switch (mutex->attr->mutex_type) { @@ -59,12 +71,14 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex, /* The lock is busy. */ self = _pthread_self (); + assert (self); if (mutex->attr) { switch (mutex->attr->mutex_type) { case PTHREAD_MUTEX_NORMAL: + assert (mutex->owner != self); break; case PTHREAD_MUTEX_ERRORCHECK: @@ -88,6 +102,10 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex, LOSE; } } + else + assert (mutex->owner != self); + + assert (mutex->owner); if (abstime && (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)) return EINVAL; @@ -123,12 +141,15 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex, else __pthread_block (self); - if (mutex->attr) + if (! mutex->attr || mutex->attr->mutex_type == PTHREAD_MUTEX_NORMAL) + { +#ifndef NDEBUG + mutex->owner = self; +#endif + } + else switch (mutex->attr->mutex_type) { - case PTHREAD_MUTEX_NORMAL: - break; - case PTHREAD_MUTEX_RECURSIVE: assert (mutex->locks == 0); mutex->locks = 1; |