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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Dec  3 17:45:47 2011 +0100

cobalt/monitor: handle async cancellation in sync ops

---

 lib/cobalt/internal.c |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 161197a..832c520 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -180,17 +180,22 @@ void cobalt_monitor_grant(cobalt_monitor_t *mon, unsigned 
long *u_mode)
 
 int cobalt_monitor_grant_sync(cobalt_monitor_t *mon, unsigned long *u_mode)
 {
-       int ret;
+       int ret, oldtype;
 
        cobalt_monitor_grant(mon, u_mode);
 
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        ret = XENOMAI_SKINCALL1(__cobalt_muxid,
                                sc_cobalt_monitor_sync,
                                mon);
-       if (ret)
+
+       pthread_setcanceltype(oldtype, NULL);
+
+       if (ret == -EINTR)
                return cobalt_monitor_enter(mon);
 
-       return 0;
+       return ret;
 }
 
 void cobalt_monitor_grant_all(cobalt_monitor_t *mon, unsigned long *u_mode)
@@ -202,17 +207,22 @@ void cobalt_monitor_grant_all(cobalt_monitor_t *mon, 
unsigned long *u_mode)
 
 int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon, unsigned long *u_mode)
 {
-       int ret;
+       int ret, oldtype;
 
        cobalt_monitor_grant_all(mon, u_mode);
 
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        ret = XENOMAI_SKINCALL1(__cobalt_muxid,
                                sc_cobalt_monitor_sync,
                                mon);
-       if (ret)
+
+       pthread_setcanceltype(oldtype, NULL);
+
+       if (ret == -EINTR)
                return cobalt_monitor_enter(mon);
 
-       return 0;
+       return ret;
 }
 
 void cobalt_monitor_drain(cobalt_monitor_t *mon)
@@ -224,17 +234,22 @@ void cobalt_monitor_drain(cobalt_monitor_t *mon)
 
 int cobalt_monitor_drain_sync(cobalt_monitor_t *mon)
 {
-       int ret;
+       int ret, oldtype;
 
        cobalt_monitor_drain(mon);
 
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        ret = XENOMAI_SKINCALL1(__cobalt_muxid,
                                sc_cobalt_monitor_sync,
                                mon);
-       if (ret)
+
+       pthread_setcanceltype(oldtype, NULL);
+
+       if (ret == -EINTR)
                return cobalt_monitor_enter(mon);
 
-       return 0;
+       return ret;
 }
 
 void cobalt_monitor_drain_all(cobalt_monitor_t *mon)
@@ -246,15 +261,20 @@ void cobalt_monitor_drain_all(cobalt_monitor_t *mon)
 
 int cobalt_monitor_drain_all_sync(cobalt_monitor_t *mon)
 {
-       int ret;
+       int ret, oldtype;
 
        cobalt_monitor_drain_all(mon);
 
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        ret = XENOMAI_SKINCALL1(__cobalt_muxid,
                                sc_cobalt_monitor_sync,
                                mon);
-       if (ret)
+
+       pthread_setcanceltype(oldtype, NULL);
+
+       if (ret == -EINTR)
                return cobalt_monitor_enter(mon);
 
-       return 0;
+       return ret;
 }


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

Reply via email to