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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Nov 21 23:48:05 2011 +0100

copperplate/threadobj: fix unprotected status reading

---

 lib/copperplate/threadobj.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 11cc571..a996b1e 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -867,7 +867,7 @@ void threadobj_start(struct threadobj *thobj)       /* 
thobj->lock held. */
 
 void threadobj_wait_start(struct threadobj *thobj) /* thobj->lock free. */
 {
-       int oldstate;
+       int oldstate, status;
 
        threadobj_lock(thobj);
 
@@ -885,7 +885,10 @@ void threadobj_wait_start(struct threadobj *thobj) /* 
thobj->lock free. */
         * pthread_cond_wait() dropped it.
         */
 
-       while ((thobj->status & (THREADOBJ_STARTED|THREADOBJ_ABORTED)) == 0) {
+       for (;;) {
+               status = thobj->status;
+               if (status & (THREADOBJ_STARTED|THREADOBJ_ABORTED))
+                       break;
                oldstate = thobj->cancel_state;
                __RT(pthread_cond_wait(&thobj->barrier, &thobj->lock));
                thobj->cancel_state = oldstate;
@@ -899,7 +902,7 @@ void threadobj_wait_start(struct threadobj *thobj) /* 
thobj->lock free. */
         * on us, so we need to go idle into a cancellation point to
         * wait for it: use pause() for this.
         */
-       while (thobj->status & THREADOBJ_ABORTED)
+       while (status & THREADOBJ_ABORTED)
                pause();
 }
 


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

Reply via email to