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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Dec 14 11:39:54 2011 +0100

lib/cobalt: make ownership check unconditional on unlocking

f1a968696 reduced the amount of runtime checks done for non
ERRORCHECK mutexes, to speed up operations in known-to-be-safe
cases. Unfortunately, several APIs want to combine recursive mutex and
check for lock imbalance upon unlocking, which puts them at odds with
this change.

We introduce back the unconditional check for lock imbalance in
__wrap_pthread_mutex_unlock() to fix this issue, without resorting to
significant overhead in client APIs.

---

 lib/cobalt/mutex.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index fb17b16..14fd454 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -289,41 +289,32 @@ int __wrap_pthread_mutex_unlock(pthread_mutex_t *mutex)
                &((union __xeno_mutex *)mutex)->shadow_mutex;
        struct mutex_dat *datp = NULL;
        xnhandle_t cur = XN_NO_HANDLE;
-       int err, check;
+       int err;
 
        if (unlikely(_mutex->magic != COBALT_MUTEX_MAGIC))
                return EINVAL;
 
-       if ((check = _mutex->attr.type == PTHREAD_MUTEX_ERRORCHECK)) {
-               cur = xeno_get_current();
-               if (cur == XN_NO_HANDLE)
-                       return EPERM;
+       cur = xeno_get_current();
+       if (cur == XN_NO_HANDLE)
+               return EPERM;
 
-               datp = mutex_get_datp(_mutex);
-               if (xnsynch_fast_owner_check(&datp->owner, cur) != 0)
-                       return EPERM;
-       }
+       datp = mutex_get_datp(_mutex);
+       if (xnsynch_fast_owner_check(&datp->owner, cur) != 0)
+               return EPERM;
 
        if (_mutex->lockcnt > 1) {
                --_mutex->lockcnt;
                return 0;
        }
 
-       if (!check)
-               datp = mutex_get_datp(_mutex);
-
        if ((datp->flags & COBALT_MUTEX_COND_SIGNAL))
                goto do_syscall;
 
        if (unlikely(xeno_get_current_mode() & XNOTHER))
                goto do_syscall;
 
-       if (!check)
-               cur = xeno_get_current();
-
        if (likely(xnsynch_fast_release(&datp->owner, cur)))
                return 0;
-
 do_syscall:
 
        do {


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

Reply via email to