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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Aug  2 20:06:47 2014 +0200

copperplate/threadobj: fix priority inversion when updating schedparams

---

 lib/copperplate/threadobj.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 48aa032..e43a8e1 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -862,10 +862,11 @@ int threadobj_stat(struct threadobj *thobj,
 
 static int request_setschedparam(struct threadobj *thobj, int policy,
                                 const struct sched_param_ex *param_ex)
-{
+{                              /* thobj->lock held */
+       int ret;
+
 #ifdef CONFIG_XENO_PSHARED
        struct remote_request *rq;
-       int ret;
 
        if (unlikely(!threadobj_local_p(thobj))) {
                rq = xnmalloc(sizeof(*rq));
@@ -883,7 +884,17 @@ static int request_setschedparam(struct threadobj *thobj, 
int policy,
                return ret;
        }
 #endif
-       return __bt(copperplate_renice_local_thread(thobj->ptid, policy, 
param_ex));
+       /*
+        * We must drop the lock temporarily across the setsched
+        * operation, as libcobalt may switch us to secondary mode
+        * when doing so (i.e. libc call to reflect the new priority
+        * on the linux side).
+        */
+       threadobj_unlock(thobj);
+       ret = __bt(copperplate_renice_local_thread(thobj->ptid, policy, 
param_ex));
+       threadobj_lock(thobj);
+
+       return ret;
 }
 
 static int request_cancel(struct threadobj *thobj) /* thobj->lock held, 
dropped. */


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

Reply via email to