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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu May 15 16:38:07 2014 +0200

copperplate: tag high-level blocking services with warn_unused_result

The return value of any such service may restrict the valid execution
flow for the caller, as a break condition may have been received, or
the target object might have become stale while sleeping.

Mark these calls with GCC's warn_unused_result attribute, to make sure
these events won't go unnoticed in the client code.

---

 include/copperplate/cluster.h   |   13 +++++++------
 include/copperplate/eventobj.h  |    5 +++--
 include/copperplate/semobj.h    |    3 ++-
 include/copperplate/syncobj.h   |   11 +++++------
 include/copperplate/threadobj.h |    8 ++++----
 lib/alchemy/task.c              |   22 +++++++++++++++-------
 lib/psos/task.c                 |    6 ++++--
 7 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/include/copperplate/cluster.h b/include/copperplate/cluster.h
index 4ec26ca..34da167 100644
--- a/include/copperplate/cluster.h
+++ b/include/copperplate/cluster.h
@@ -115,7 +115,7 @@ int pvsyncluster_delobj(struct pvsyncluster *sc,
 int pvsyncluster_findobj(struct pvsyncluster *sc,
                         const char *name,
                         const struct timespec *timeout,
-                        struct pvclusterobj **cobjp);
+                        struct pvclusterobj **cobjp) __must_check;
 
 #ifdef CONFIG_XENO_PSHARED
 
@@ -144,7 +144,7 @@ int syncluster_delobj(struct syncluster *sc,
 int syncluster_findobj(struct syncluster *sc,
                       const char *name,
                       const struct timespec *timeout,
-                      struct clusterobj **cobjp);
+                      struct clusterobj **cobjp) __must_check;
 
 #else /* !CONFIG_XENO_PSHARED */
 
@@ -196,10 +196,11 @@ static inline int syncluster_delobj(struct syncluster *sc,
        return pvsyncluster_delobj(sc, cobj);
 }
 
-static inline int syncluster_findobj(struct syncluster *sc,
-                                    const char *name,
-                                    const struct timespec *timeout,
-                                    struct clusterobj **cobjp)
+static inline  __must_check
+int syncluster_findobj(struct syncluster *sc,
+                      const char *name,
+                      const struct timespec *timeout,
+                      struct clusterobj **cobjp)
 {
        return pvsyncluster_findobj(sc, name, timeout, cobjp);
 }
diff --git a/include/copperplate/eventobj.h b/include/copperplate/eventobj.h
index 9b2a5bb..f40bfda 100644
--- a/include/copperplate/eventobj.h
+++ b/include/copperplate/eventobj.h
@@ -19,6 +19,7 @@
 #ifndef _COPPERPLATE_EVENTOBJ_H
 #define _COPPERPLATE_EVENTOBJ_H
 
+#include <boilerplate/compiler.h>
 #include <copperplate/reference.h>
 
 struct eventobj_waitentry {
@@ -77,7 +78,7 @@ extern "C" {
 
 int eventobj_init(struct eventobj *evobj,
                  unsigned long value, int flags,
-                 fnref_type(void (*)(struct eventobj *evobj)) finalizer);
+                 fnref_type(void (*)(struct eventobj *evobj)) finalizer) 
__must_check;
 
 int eventobj_destroy(struct eventobj *evobj);
 
@@ -88,7 +89,7 @@ int eventobj_wait(struct eventobj *evobj,
                  unsigned long bits,
                  unsigned long *bits_r,
                  int mode,
-                 const struct timespec *timeout);
+                 const struct timespec *timeout) __must_check;
 
 int eventobj_clear(struct eventobj *evobj,
                   unsigned long bits,
diff --git a/include/copperplate/semobj.h b/include/copperplate/semobj.h
index f5de528..dd2e642 100644
--- a/include/copperplate/semobj.h
+++ b/include/copperplate/semobj.h
@@ -19,6 +19,7 @@
 #ifndef _COPPERPLATE_SEMOBJ_H
 #define _COPPERPLATE_SEMOBJ_H
 
+#include <boilerplate/compiler.h>
 #include <copperplate/reference.h>
 
 struct semobj_waitentry {
@@ -70,7 +71,7 @@ int semobj_post(struct semobj *smobj);
 int semobj_broadcast(struct semobj *smobj);
 
 int semobj_wait(struct semobj *smobj,
-               const struct timespec *timeout);
+               const struct timespec *timeout) __must_check;
 
 int semobj_getvalue(struct semobj *smobj, int *sval);
 
diff --git a/include/copperplate/syncobj.h b/include/copperplate/syncobj.h
index d8a6ade..b0f2ffd 100644
--- a/include/copperplate/syncobj.h
+++ b/include/copperplate/syncobj.h
@@ -130,13 +130,12 @@ int __syncobj_broadcast_drain(struct syncobj *sobj, int 
reason);
 
 int __syncobj_broadcast_grant(struct syncobj *sobj, int reason);
 
-int __must_check
-syncobj_init(struct syncobj *sobj, clockid_t clk_id, int flags,
-            fnref_type(void (*)(struct syncobj *sobj)) finalizer);
+int syncobj_init(struct syncobj *sobj, clockid_t clk_id, int flags,
+                fnref_type(void (*)(struct syncobj *sobj)) finalizer) 
__must_check;
 
 int syncobj_wait_grant(struct syncobj *sobj,
                 const struct timespec *timeout,
-                struct syncstate *syns);
+                struct syncstate *syns) __must_check;
 
 struct threadobj *syncobj_grant_one(struct syncobj *sobj);
 
@@ -148,14 +147,14 @@ struct threadobj *syncobj_peek_grant(struct syncobj 
*sobj);
 struct threadobj *syncobj_peek_drain(struct syncobj *sobj);
 
 int syncobj_lock(struct syncobj *sobj,
-                struct syncstate *syns);
+                struct syncstate *syns) __must_check;
 
 void syncobj_unlock(struct syncobj *sobj,
                    struct syncstate *syns);
 
 int syncobj_wait_drain(struct syncobj *sobj,
                       const struct timespec *timeout,
-                      struct syncstate *syns);
+                      struct syncstate *syns) __must_check;
 
 int syncobj_destroy(struct syncobj *sobj,
                    struct syncstate *syns);
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5ca753c..8603534 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -290,10 +290,10 @@ static inline void threadobj_free(struct threadobj *thobj)
        __threadobj_free((unsigned char *)thobj - thobj->core_offset);
 }
 
-int __must_check threadobj_init(struct threadobj *thobj,
-                               struct threadobj_init_data *idata);
+int threadobj_init(struct threadobj *thobj,
+                  struct threadobj_init_data *idata) __must_check;
 
-int threadobj_start(struct threadobj *thobj);
+int threadobj_start(struct threadobj *thobj) __must_check;
 
 void threadobj_shadow(struct threadobj *thobj);
 
@@ -336,7 +336,7 @@ int threadobj_set_periodic(struct threadobj *thobj,
                           const struct timespec *__restrict__ idate,
                           const struct timespec *__restrict__ period);
 
-int threadobj_wait_period(unsigned long *overruns_r);
+int threadobj_wait_period(unsigned long *overruns_r) __must_check;
 
 void threadobj_spin(ticks_t ns);
 
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index 86ffb68..380e265 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -170,6 +170,7 @@ static void task_finalizer(struct threadobj *thobj)
 {
        struct alchemy_task *tcb;
        struct syncstate syns;
+       int ret;
 
        tcb = container_of(thobj, struct alchemy_task, thobj);
        registry_destroy_file(&tcb->fsobj);
@@ -178,8 +179,9 @@ static void task_finalizer(struct threadobj *thobj)
         * The msg sync may be pended by other threads, so we do have
         * to use syncobj_destroy() on it (i.e. NOT syncobj_uninit()).
         */
-       __bt(syncobj_lock(&tcb->sobj_msg, &syns));
-       syncobj_destroy(&tcb->sobj_msg, &syns);
+       ret = __bt(syncobj_lock(&tcb->sobj_msg, &syns));
+       if (ret == 0)
+               syncobj_destroy(&tcb->sobj_msg, &syns);
 }
 
 static int task_prologue_1(void *arg)
@@ -1833,14 +1835,18 @@ int rt_task_receive_timed(RT_TASK_MCB *mcb_r,
 
        CANCEL_DEFER(svc);
 
-       __bt(syncobj_lock(&current->sobj_msg, &syns));
+       ret = syncobj_lock(&current->sobj_msg, &syns);
+       if (ret)
+               goto out;
 
        while (!syncobj_grant_wait_p(&current->sobj_msg)) {
                if (alchemy_poll_mode(abs_timeout)) {
                        ret = -EWOULDBLOCK;
                        goto done;
                }
-               syncobj_wait_drain(&current->sobj_msg, abs_timeout, &syns);
+               ret = syncobj_wait_drain(&current->sobj_msg, abs_timeout, 
&syns);
+               if (ret)
+                       goto done;
        }
 
        thobj = syncobj_peek_grant(&current->sobj_msg);
@@ -1862,7 +1868,7 @@ fixup:
        mcb_r->size = mcb_s->size;
 done:
        syncobj_unlock(&current->sobj_msg, &syns);
-
+out:
        CANCEL_RESTORE(svc);
 
        return ret;
@@ -1949,7 +1955,9 @@ int rt_task_reply(int flowid, RT_TASK_MCB *mcb_s)
 
        CANCEL_DEFER(svc);
 
-       __bt(syncobj_lock(&current->sobj_msg, &syns));
+       ret = __bt(syncobj_lock(&current->sobj_msg, &syns));
+       if (ret)
+               goto out;
 
        ret = -ENXIO;
        if (!syncobj_grant_wait_p(&current->sobj_msg))
@@ -1986,7 +1994,7 @@ int rt_task_reply(int flowid, RT_TASK_MCB *mcb_s)
        mcb_r->opcode = mcb_s ? mcb_s->opcode : 0;
 done:
        syncobj_unlock(&current->sobj_msg, &syns);
-
+out:
        CANCEL_RESTORE(svc);
 
        return ret;
diff --git a/lib/psos/task.c b/lib/psos/task.c
index de7c295..ddfe54e 100644
--- a/lib/psos/task.c
+++ b/lib/psos/task.c
@@ -156,6 +156,7 @@ static void task_finalizer(struct threadobj *thobj)
        struct psos_task *task = container_of(thobj, struct psos_task, thobj);
        struct psos_tm *tm, *tmp;
        struct syncstate syns;
+       int ret;
 
        cluster_delobj(&psos_task_table, &task->cobj);
 
@@ -165,8 +166,9 @@ static void task_finalizer(struct threadobj *thobj)
        }
 
        /* We have to hold a lock on a syncobj to destroy it. */
-       syncobj_lock(&task->sobj, &syns);
-       syncobj_destroy(&task->sobj, &syns);
+       ret = __bt(syncobj_lock(&task->sobj, &syns));
+       if (ret == 0)
+               syncobj_destroy(&task->sobj, &syns);
 }
 
 static int task_prologue(void *arg)


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

Reply via email to