]> git.saurik.com Git - apple/libpthread.git/blobdiff - src/pthread_rwlock.c
libpthread-218.51.1.tar.gz
[apple/libpthread.git] / src / pthread_rwlock.c
index c7b5373a87893dfc42a439baca50194f0c9a2687..4f461a33b971418c34f2ad18f0e2dcc832e5ab02 100644 (file)
@@ -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;
 }