]> git.saurik.com Git - apple/libpthread.git/blobdiff - src/pthread_cond.c
libpthread-218.60.3.tar.gz
[apple/libpthread.git] / src / pthread_cond.c
index a425fbedb62fd621c64bfa0a42a594306b794587..cc8e7d8b473bb962e02c353ddcfcc0553997c226 100644 (file)
@@ -163,24 +163,34 @@ _pthread_cond_init(_pthread_cond *cond, const pthread_condattr_t *attr, int conf
        return 0;
 }
 
+PTHREAD_NOINLINE
 static int
-_pthread_cond_check_init(_pthread_cond *cond, bool *inited)
+_pthread_cond_check_init_slow(_pthread_cond *cond, bool *inited)
 {
-       int res = 0;
-       if (cond->sig != _PTHREAD_COND_SIG) {
-               res = EINVAL;
+       int res = EINVAL;
+       if (cond->sig == _PTHREAD_COND_SIG_init) {
+               _PTHREAD_LOCK(cond->lock);
                if (cond->sig == _PTHREAD_COND_SIG_init) {
-                       LOCK(cond->lock);
-                       if (cond->sig == _PTHREAD_COND_SIG_init) {
-                               res = _pthread_cond_init(cond, NULL, 0);
-                               if (inited) {
-                                       *inited = true;
-                               }
-                       } else if (cond->sig == _PTHREAD_COND_SIG) {
-                               res = 0;
+                       res = _pthread_cond_init(cond, NULL, 0);
+                       if (inited) {
+                               *inited = true;
                        }
-                       UNLOCK(cond->lock);
+               } else if (cond->sig == _PTHREAD_COND_SIG) {
+                       res = 0;
                }
+               _PTHREAD_UNLOCK(cond->lock);
+       } else if (cond->sig == _PTHREAD_COND_SIG) {
+               res = 0;
+       }
+       return res;
+}
+
+static inline int
+_pthread_cond_check_init(_pthread_cond *cond, bool *inited)
+{
+       int res = 0;
+       if (cond->sig != _PTHREAD_COND_SIG) {
+               return _pthread_cond_check_init_slow(cond, inited);
        }
        return res;
 }
@@ -191,7 +201,7 @@ pthread_cond_destroy(pthread_cond_t *ocond)
        _pthread_cond *cond = (_pthread_cond *)ocond;
        int res = EINVAL;
        if (cond->sig == _PTHREAD_COND_SIG) {
-               LOCK(cond->lock);
+               _PTHREAD_LOCK(cond->lock);
 
                uint64_t oldval64, newval64;
                uint32_t lcntval, ucntval, scntval;
@@ -224,7 +234,7 @@ pthread_cond_destroy(pthread_cond_t *ocond)
                cond->sig = _PTHREAD_NO_SIG;
                res = 0;
                
-               UNLOCK(cond->lock);
+               _PTHREAD_UNLOCK(cond->lock);
 
                if (needclearpre) {
                        (void)__psynch_cvclrprepost(cond, lcntval, ucntval, scntval, 0, lcntval, flags);
@@ -432,7 +442,8 @@ extern void _pthread_testcancel(pthread_t thread, int isconforming);
        }
 
        if (isconforming) {
-               if (mutex->sig != _PTHREAD_MUTEX_SIG && (mutex->sig & _PTHREAD_MUTEX_SIG_init_MASK) != _PTHREAD_MUTEX_SIG_CMP) {
+               if (!_pthread_mutex_check_signature(mutex) &&
+                               !_pthread_mutex_check_signature_init(mutex)) {
                        return EINVAL;
                }
                if (isconforming > 0) {
@@ -568,9 +579,9 @@ _pthread_cond_cleanup(void *arg)
        pthread_t thread = pthread_self();
        int thcanceled = 0;
 
-       LOCK(thread->lock);
+       _PTHREAD_LOCK(thread->lock);
        thcanceled = (thread->detached & _PTHREAD_WASCANCEL);
-       UNLOCK(thread->lock);
+       _PTHREAD_UNLOCK(thread->lock);
 
        if (thcanceled == 0) {
                return;
@@ -689,6 +700,6 @@ pthread_cond_init(pthread_cond_t *ocond, const pthread_condattr_t *attr)
 #endif /* __DARWIN_UNIX03 */
 
        _pthread_cond *cond = (_pthread_cond *)ocond;
-       LOCK_INIT(cond->lock);
+       _PTHREAD_LOCK_INIT(cond->lock);
        return _pthread_cond_init(cond, attr, conforming);
 }