Module: xenomai-2.6
Branch: master
Commit: ae32d56521f8393382e5645aba03393c7a3f98ef
URL:    
http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=ae32d56521f8393382e5645aba03393c7a3f98ef

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Jan 29 17:32:49 2012 +0100

posix: cosmetic fixes in src/skins/posix/mutex.c

---

 src/skins/posix/mutex.c |  107 ++++++++++++++++++++++++-----------------------
 1 files changed, 54 insertions(+), 53 deletions(-)

diff --git a/src/skins/posix/mutex.c b/src/skins/posix/mutex.c
index a08a30d..6917c86 100644
--- a/src/skins/posix/mutex.c
+++ b/src/skins/posix/mutex.c
@@ -154,15 +154,13 @@ int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex)
        xnhandle_t cur;
 
        cur = xeno_get_current();
-       if (cur == XN_NO_HANDLE)
+       if (unlikely(cur == XN_NO_HANDLE))
                return EPERM;
 
-       status = xeno_get_current_mode();
-
        if (unlikely(cb_try_read_lock(&shadow->lock, s)))
                return EINVAL;
 
-       if (shadow->magic != PSE51_MUTEX_MAGIC) {
+       if (unlikely(shadow->magic != PSE51_MUTEX_MAGIC)) {
                err = -EINVAL;
                goto out;
        }
@@ -172,34 +170,37 @@ int __wrap_pthread_mutex_lock(pthread_mutex_t *mutex)
         * order to handle the auto-relax feature, so we must always
         * obtain them via a syscall.
         */
-       if (likely(!(status & (XNRELAX|XNOTHER)))) {
-               err = xnsynch_fast_acquire(get_ownerp(shadow), cur);
+       status = xeno_get_current_mode();
+       if (unlikely(status & (XNRELAX|XNOTHER)))
+               goto do_syscall;
 
-               if (likely(!err)) {
-                       shadow->lockcnt = 1;
-                       cb_read_unlock(&shadow->lock, s);
-                       return 0;
-               }
+       err = xnsynch_fast_acquire(get_ownerp(shadow), cur);
+       if (likely(!err)) {
+               shadow->lockcnt = 1;
+               cb_read_unlock(&shadow->lock, s);
+               return 0;
+       }
 
-               if (err == -EBUSY)
-                       switch(shadow->attr.type) {
-                       case PTHREAD_MUTEX_NORMAL:
-                               break;
+       if (err == -EBUSY)
+               switch(shadow->attr.type) {
+               case PTHREAD_MUTEX_NORMAL:
+                       break;
 
-                       case PTHREAD_MUTEX_ERRORCHECK:
-                               err = -EDEADLK;
-                               goto out;
+               case PTHREAD_MUTEX_ERRORCHECK:
+                       err = -EDEADLK;
+                       goto out;
 
-                       case PTHREAD_MUTEX_RECURSIVE:
-                               if (shadow->lockcnt == UINT_MAX) {
-                                       err = -EAGAIN;
-                                       goto out;
-                               }
-                               ++shadow->lockcnt;
-                               err = 0;
+               case PTHREAD_MUTEX_RECURSIVE:
+                       if (shadow->lockcnt == UINT_MAX) {
+                               err = -EAGAIN;
                                goto out;
                        }
+                       ++shadow->lockcnt;
+                       err = 0;
+                       goto out;
                }
+
+  do_syscall:
 #endif /* CONFIG_XENO_FASTSYNCH */
 
        do {
@@ -226,48 +227,49 @@ int __wrap_pthread_mutex_timedlock(pthread_mutex_t *mutex,
        xnhandle_t cur;
 
        cur = xeno_get_current();
-       if (cur == XN_NO_HANDLE)
+       if (unlikely(cur == XN_NO_HANDLE))
                return EPERM;
 
-       status = xeno_get_current_mode();
-
        if (unlikely(cb_try_read_lock(&shadow->lock, s)))
                return EINVAL;
 
-       if (shadow->magic != PSE51_MUTEX_MAGIC) {
+       if (unlikely(shadow->magic != PSE51_MUTEX_MAGIC)) {
                err = -EINVAL;
                goto out;
        }
 
        /* See __wrap_pthread_mutex_lock() */
-       if (likely(!(status & (XNRELAX|XNOTHER)))) {
-               err = xnsynch_fast_acquire(get_ownerp(shadow), cur);
+       status = xeno_get_current_mode();
+       if (unlikely(status & (XNRELAX|XNOTHER)))
+               goto do_syscall;
 
-               if (likely(!err)) {
-                       shadow->lockcnt = 1;
-                       cb_read_unlock(&shadow->lock, s);
-                       return 0;
-               }
+       err = xnsynch_fast_acquire(get_ownerp(shadow), cur);
+       if (likely(!err)) {
+               shadow->lockcnt = 1;
+               cb_read_unlock(&shadow->lock, s);
+               return 0;
+       }
 
-               if (err == -EBUSY)
-                       switch(shadow->attr.type) {
-                       case PTHREAD_MUTEX_NORMAL:
-                               break;
+       if (err == -EBUSY)
+               switch(shadow->attr.type) {
+               case PTHREAD_MUTEX_NORMAL:
+                       break;
 
-                       case PTHREAD_MUTEX_ERRORCHECK:
-                               err = -EDEADLK;
-                               goto out;
-
-                       case PTHREAD_MUTEX_RECURSIVE:
-                               if (shadow->lockcnt == UINT_MAX) {
-                                       err = -EAGAIN;
-                                       goto out;
-                               }
+               case PTHREAD_MUTEX_ERRORCHECK:
+                       err = -EDEADLK;
+                       goto out;
 
-                               ++shadow->lockcnt;
+               case PTHREAD_MUTEX_RECURSIVE:
+                       if (shadow->lockcnt == UINT_MAX) {
+                               err = -EAGAIN;
                                goto out;
                        }
-       }
+
+                       ++shadow->lockcnt;
+                       goto out;
+               }
+
+  do_syscall:
 #endif /* CONFIG_XENO_FASTSYNCH */
 
        do {
@@ -381,8 +383,6 @@ int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex)
        if (cur == XN_NO_HANDLE)
                return EPERM;
 
-       status = xeno_get_current_mode();
-
        if (unlikely(cb_try_read_lock(&shadow->lock, s)))
                return EINVAL;
 
@@ -391,6 +391,7 @@ int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex)
                goto out_err;
        }
 
+       status = xeno_get_current_mode();
        if (unlikely(status & XNOTHER))
                goto do_syscall;
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to