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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Apr 23 15:42:57 2014 +0200

boilerplate/lock: include cancelability state in safety check

---

 lib/boilerplate/ancillaries.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 2d5f532..fc58afd 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -209,15 +209,21 @@ __attribute__ ((weak)) void *__main_heap = NULL;
 
 int __check_cancel_type(const char *locktype)
 {
-       int oldtype;
+       int oldtype, oldstate;
 
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
-       if (oldtype != PTHREAD_CANCEL_DEFERRED) {
-               warning("%s_nocancel() section is NOT cancel-safe", locktype);
-               return __bt(-EINVAL);
-       }
+       if (oldtype == PTHREAD_CANCEL_DEFERRED)
+               return 0;
+
+       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
+       if (oldstate == PTHREAD_CANCEL_DISABLE)
+               return 0;
+
+       abort();
+       warning("%s_nocancel() section is NOT cancel-safe", locktype);
+       pthread_setcancelstate(oldstate, NULL);
 
-       return 0;
+       return __bt(-EINVAL);
 }
 
 #endif /* CONFIG_XENO_DEBUG */


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

Reply via email to