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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Sep  4 17:17:31 2013 +0200

copperplate/threadobj: introduce __threadobj_set_scheduler()

This is an internal helper aimed at tracking changes to the thread
priority, without performing any other related fixups. We use this in
POSIX-based APIs to resync the copperplate thread state with external
updates done directly via the pthread_setschedparam() service.

This helper should disappear when we actually implement a copperplate
service to set any arbitrary policy and scheduling parameters, in
replacement of threadobj_set_priority() - which is logically broken
and uselessly restrictive.

---

 include/copperplate/threadobj.h |    3 +++
 lib/copperplate/threadobj.c     |   36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 62515d7..51dc062 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -310,6 +310,9 @@ int __threadobj_unlock_sched(struct threadobj *current);
 
 int threadobj_unlock_sched(void);
 
+void __threadobj_set_scheduler(struct threadobj *thobj,
+                              int policy, int prio);
+
 int threadobj_set_priority(struct threadobj *thobj, int prio);
 
 int threadobj_set_mode(int clrmask, int setmask, int *mode_r);
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 08c8ea2..d2f7d67 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -224,6 +224,19 @@ int threadobj_unlock_sched(void)
        return __bt(__threadobj_unlock_sched(current));
 }
 
+void __threadobj_set_scheduler(struct threadobj *thobj,
+                              int policy, int prio) /* thobj->lock held */
+{
+       __threadobj_check_locked(thobj);
+
+       /*
+        * XXX: Internal call which bypasses the normal scheduling
+        * policy tracking: use with care.
+        */
+       thobj->priority = prio;
+       thobj->policy = policy;
+}
+
 int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock 
held, dropped */
 {
        struct sched_param_ex xparam;
@@ -565,6 +578,24 @@ int threadobj_unlock_sched(void)
        return __bt(ret);
 }
 
+void __threadobj_set_scheduler(struct threadobj *thobj,
+                              int policy, int prio) /* thobj->lock held */
+{
+       __threadobj_check_locked(thobj);
+
+       /*
+        * XXX: Internal call which bypasses the normal scheduling
+        * policy tracking: use with care.
+        */
+       if (thobj->schedlock_depth > 0) {
+               thobj->core.prio_unlocked = prio;
+               thobj->core.policy_unlocked = policy;
+       } else {
+               thobj->priority = prio;
+               thobj->policy = policy;
+       }
+}
+
 int threadobj_set_priority(struct threadobj *thobj, int prio) /* thobj->lock 
held, dropped */
 {
        pthread_t tid = thobj->tid;
@@ -585,12 +616,12 @@ int threadobj_set_priority(struct threadobj *thobj, int 
prio) /* thobj->lock hel
                return 0;
        }
 
-       thobj->priority = prio;
        policy = SCHED_RT;
        if (prio == 0) {
                thobj->status &= ~__THREAD_S_RR;
                policy = SCHED_OTHER;
-       }
+       } else if (thobj->status & __THREAD_S_RR)
+               policy = SCHED_RR;
 
        thobj->priority = prio;
        thobj->policy = policy;
@@ -900,6 +931,7 @@ int threadobj_start(struct threadobj *thobj)        /* 
thobj->lock held. */
 
        if (current && thobj->priority <= current->priority)
                return 0;
+
        /*
         * Caller needs synchronization with the thread being started,
         * which has higher priority. We shall wait until that thread


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

Reply via email to