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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Dec 13 11:12:44 2011 +0100

vxworks/semLib: fix SEM_DELETE_SAFE handling, Cobalt support

---

 lib/vxworks/semLib.c |   20 +++++++++++---------
 lib/vxworks/semLib.h |    2 ++
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/vxworks/semLib.c b/lib/vxworks/semLib.c
index d1a8b07..90fd381 100644
--- a/lib/vxworks/semLib.c
+++ b/lib/vxworks/semLib.c
@@ -229,28 +229,30 @@ static STATUS msem_take(struct wind_sem *sem, int timeout)
        if (threadobj_irq_p())
                return S_intLib_NOT_ISR_CALLABLE;
 
+       /*
+        * We allow threads from other APIs to grab a VxWorks mutex
+        * ignoring the safe option in such a case.
+        */
        current = wind_task_current();
-       if (current != NULL && (sem->options & SEM_DELETE_SAFE))
+       if (current && (sem->options & SEM_DELETE_SAFE))
                __RT(pthread_mutex_lock(&current->safelock));
 
        if (timeout == NO_WAIT) {
                ret = __RT(pthread_mutex_trylock(&sem->u.msem.lock));
-               if (ret)
-                       goto done;
-               return OK;
+               goto check;
        }
 
        if  (timeout == WAIT_FOREVER) {
                ret = __RT(pthread_mutex_lock(&sem->u.msem.lock));
-               if (ret)
-                       goto done;
-               return OK;
+               goto check;
        }
 
        __clockobj_ticks_to_timeout(&wind_clock, CLOCK_REALTIME, timeout, &ts);
        ret = __RT(pthread_mutex_timedlock(&sem->u.msem.lock, &ts));
-done:
+check:
        switch (ret) {
+       case 0:
+               return OK;
        case EINVAL:
                ret = S_objLib_OBJ_ID_ERROR;
                break;
@@ -289,7 +291,7 @@ static STATUS msem_give(struct wind_sem *sem)
 
        if (sem->options & SEM_DELETE_SAFE) {
                current = wind_task_current();
-               if (current != NULL)
+               if (current)
                        __RT(pthread_mutex_unlock(&current->safelock));
        }
 
diff --git a/lib/vxworks/semLib.h b/lib/vxworks/semLib.h
index f9a107c..f863bf0 100644
--- a/lib/vxworks/semLib.h
+++ b/lib/vxworks/semLib.h
@@ -46,6 +46,8 @@ struct wind_sem {
                } xsem;
                struct {
                        pthread_mutex_t lock;
+                       struct threadobj *owner;
+                       int lockdepth;
                } msem;
        } u;
 


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

Reply via email to