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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Aug 28 10:51:16 2013 +0200

copperplate/cobalt: threadobj_set_mode() must track nested locking calls

---

 include/copperplate/threadobj.h |    2 +-
 lib/copperplate/threadobj.c     |   25 +++++++++++++++----------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index cfd8fc4..97985ff 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -407,7 +407,7 @@ static inline int threadobj_lock_sched_once(void)
        if (current->schedlock_depth == 0)
                return threadobj_lock_sched();
 
-       return 0;
+       return -EBUSY;
 }
 
 static inline void threadobj_yield(void)
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index b8c4fb2..8761571 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -252,11 +252,6 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current->lock h
 
        __threadobj_check_locked(current);
 
-       if (setmask & __THREAD_M_LOCK)
-               __setmask |= PTHREAD_LOCK_SCHED;
-       else if (clrmask & __THREAD_M_LOCK)
-               __clrmask |= PTHREAD_LOCK_SCHED;
-
        if (setmask & __THREAD_M_WARNSW)
                __setmask |= PTHREAD_WARNSW;
        else if (clrmask & __THREAD_M_WARNSW)
@@ -267,7 +262,15 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current->lock h
        else if (clrmask & __THREAD_M_CONFORMING)
                __clrmask |= PTHREAD_CONFORMING;
 
-       return __bt(pthread_set_mode_np(__clrmask, __setmask, mode_r));
+       if (setmask & __THREAD_M_LOCK)
+               threadobj_lock_sched_once();
+       else if (clrmask & __THREAD_M_LOCK)
+               threadobj_unlock_sched();
+
+       if (mode_r || __setmask || __clrmask)
+               return __bt(-pthread_set_mode_np(__clrmask, __setmask, mode_r));
+
+       return 0;
 }
 
 static int set_rr(struct threadobj *thobj, struct timespec *quantum)
@@ -581,15 +584,17 @@ int threadobj_set_mode(int clrmask, int setmask, int 
*mode_r) /* current->lock h
        if (current->status & __THREAD_S_NOPREEMPT)
                old |= __THREAD_M_LOCK;
 
-       if (setmask & __THREAD_M_LOCK)
-               ret = __bt(threadobj_lock_sched_once());
-       else if (clrmask & __THREAD_M_LOCK)
+       if (setmask & __THREAD_M_LOCK) {
+               ret = threadobj_lock_sched_once();
+               if (ret == -EBUSY)
+                       ret = 0;
+       } else if (clrmask & __THREAD_M_LOCK)
                threadobj_unlock_sched();
 
        if (mode_r)
                *mode_r = old;
 
-       return ret;
+       return __bt(ret);
 }
 
 static inline int set_rr(struct threadobj *thobj, struct timespec *quantum)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to