X-Git-Url: https://git.saurik.com/apple/libpthread.git/blobdiff_plain/f1a1da6cf65a9d0e6858678f6c259025cf5d27fd..010efe49ed19075418796acfb56075924aa43936:/src/pthread_rwlock.c diff --git a/src/pthread_rwlock.c b/src/pthread_rwlock.c index c7b5373..4f461a3 100644 --- a/src/pthread_rwlock.c +++ b/src/pthread_rwlock.c @@ -302,31 +302,45 @@ pthread_rwlock_init(pthread_rwlock_t *orwlock, const pthread_rwlockattr_t *attr) } #endif if (res == 0) { - LOCK_INIT(rwlock->lock); + _PTHREAD_LOCK_INIT(rwlock->lock); res = __pthread_rwlock_init(rwlock, attr); } return res; } +PTHREAD_NOINLINE +static int +_pthread_rwlock_check_init_slow(pthread_rwlock_t *orwlock) +{ + int res = EINVAL; + _pthread_rwlock *rwlock = (_pthread_rwlock *)orwlock; + + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + _PTHREAD_LOCK(rwlock->lock); + if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { + res = __pthread_rwlock_init(rwlock, NULL); + } else if (rwlock->sig == _PTHREAD_RWLOCK_SIG){ + res = 0; + } + _PTHREAD_UNLOCK(rwlock->lock); + } else if (rwlock->sig == _PTHREAD_RWLOCK_SIG){ + res = 0; + } + if (res != 0) { + PLOCKSTAT_RW_ERROR(orwlock, READ_LOCK_PLOCKSTAT, res); + } + return res; +} + +PTHREAD_ALWAYS_INLINE static int _pthread_rwlock_check_init(pthread_rwlock_t *orwlock) { int res = 0; _pthread_rwlock *rwlock = (_pthread_rwlock *)orwlock; + if (rwlock->sig != _PTHREAD_RWLOCK_SIG) { - res = EINVAL; - if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { - LOCK(rwlock->lock); - if (rwlock->sig == _PTHREAD_RWLOCK_SIG_init) { - res = __pthread_rwlock_init(rwlock, NULL); - } else if (rwlock->sig == _PTHREAD_RWLOCK_SIG){ - res = 0; - } - UNLOCK(rwlock->lock); - } - if (res != 0) { - PLOCKSTAT_RW_ERROR(orwlock, READ_LOCK_PLOCKSTAT, res); - } + return _pthread_rwlock_check_init_slow(orwlock); } return res; }