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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Feb  7 18:12:41 2014 +0100

copperplate/threadobj: align threadobj_current() with threadobj_current_p()

threadobj_current() has to return NULL for both non-copperplate and
copperplate-IRQ threads, for consistency with its common usage, and
threadobj_current_p() as well.

This fixes a crash when panic()ing over the timer handler thread,
which is assigned an invalid but non-NULL "current" pointer.

---

 include/copperplate/threadobj.h |   17 +++++++++++------
 lib/copperplate/syncobj.c       |    3 ++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 3529ca1..0bf6903 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -213,7 +213,7 @@ static inline void threadobj_set_current(struct threadobj 
*thobj)
        pthread_setspecific(threadobj_tskey, thobj);
 }
 
-static inline struct threadobj *threadobj_current(void)
+static inline struct threadobj *__threadobj_get_current(void)
 {
        return __threadobj_current;
 }
@@ -225,13 +225,19 @@ static inline void threadobj_set_current(struct threadobj 
*thobj)
        pthread_setspecific(threadobj_tskey, thobj);
 }
 
-static inline struct threadobj *threadobj_current(void)
+static inline struct threadobj *__threadobj_get_current(void)
 {
-       return pthread_getspecific(threadobj_tskey);
+       return (struct threadobj *)pthread_getspecific(threadobj_tskey);
 }
 
 #endif /* !HAVE_TLS */
 
+static inline struct threadobj *threadobj_current(void)
+{
+       struct threadobj *thobj = __threadobj_get_current();
+       return thobj == NULL || thobj == THREADOBJ_IRQCONTEXT ? NULL : thobj;
+}
+
 #ifdef __XENO_DEBUG__
 
 static inline void __threadobj_tag_locked(struct threadobj *thobj)
@@ -401,14 +407,13 @@ static inline int threadobj_unlock(struct threadobj 
*thobj)
 
 static inline int threadobj_irq_p(void)
 {
-       struct threadobj *current = threadobj_current();
+       struct threadobj *current = __threadobj_get_current();
        return current == THREADOBJ_IRQCONTEXT;
 }
 
 static inline int threadobj_current_p(void)
 {
-       struct threadobj *current = threadobj_current();
-       return current && current != THREADOBJ_IRQCONTEXT;
+       return threadobj_current() != NULL;
 }
 
 static inline int __threadobj_lock_sched_once(struct threadobj *current)
diff --git a/lib/copperplate/syncobj.c b/lib/copperplate/syncobj.c
index a541a87..6849f67 100644
--- a/lib/copperplate/syncobj.c
+++ b/lib/copperplate/syncobj.c
@@ -229,7 +229,8 @@ int syncobj_lock(struct syncobj *sobj, struct syncstate 
*syns)
 {
        int ret, oldstate;
 
-       assert(threadobj_current() != NULL);
+       /* Allow entry from copperplate's regular or IRQ threads. */
+       assert(__threadobj_get_current() != NULL);
 
        /*
         * This magic prevents concurrent locking while a deletion is


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

Reply via email to