Module: xenomai-3
Branch: wip/prioceil
Commit: 3847e618c2789a9c4f633d267179312db06ff64d
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3847e618c2789a9c4f633d267179312db06ff64d

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Feb 26 18:38:24 2016 +0100

lib/smokey: add timed wait on barrier

Add this chance, fix a potential UMR in smokey_barrier_wait().

---

 include/smokey/smokey.h |    3 +++
 lib/smokey/helpers.c    |   20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/smokey/smokey.h b/include/smokey/smokey.h
index 82e2b64..8351563 100644
--- a/include/smokey/smokey.h
+++ b/include/smokey/smokey.h
@@ -226,6 +226,9 @@ void smokey_barrier_destroy(struct smokey_barrier *b);
 
 int smokey_barrier_wait(struct smokey_barrier *b);
 
+int smokey_barrier_timedwait(struct smokey_barrier *b,
+                            struct timespec *ts);
+  
 void smokey_barrier_release(struct smokey_barrier *b);
        
 #ifdef __cplusplus
diff --git a/lib/smokey/helpers.c b/lib/smokey/helpers.c
index b52afed..2b9985d 100644
--- a/lib/smokey/helpers.c
+++ b/lib/smokey/helpers.c
@@ -199,7 +199,7 @@ void smokey_barrier_destroy(struct smokey_barrier *b)
 
 int smokey_barrier_wait(struct smokey_barrier *b)
 {
-       int ret;
+       int ret = 0;
        
        __RT(pthread_mutex_lock(&b->lock));
 
@@ -214,6 +214,24 @@ int smokey_barrier_wait(struct smokey_barrier *b)
        return ret;
 }
 
+int smokey_barrier_timedwait(struct smokey_barrier *b, struct timespec *ts)
+{
+       int ret = 0;
+       
+       __RT(pthread_mutex_lock(&b->lock));
+
+       while (!b->signaled) {
+               ret = __RT(pthread_cond_timedwait(&b->barrier,
+                                                 &b->lock, ts));
+               if (ret)
+                       break;
+       }
+
+       __RT(pthread_mutex_unlock(&b->lock));
+
+       return ret;
+}
+
 void smokey_barrier_release(struct smokey_barrier *b)
 {
        __RT(pthread_mutex_lock(&b->lock));


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

Reply via email to