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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Oct 17 17:43:52 2014 +0200

testsuite/smokey: xddp: fix race on connection setup

---

 testsuite/smokey/xddp/xddp.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/testsuite/smokey/xddp/xddp.c b/testsuite/smokey/xddp/xddp.c
index e447fab..6dca6e6 100644
--- a/testsuite/smokey/xddp/xddp.c
+++ b/testsuite/smokey/xddp/xddp.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <string.h>
+#include <semaphore.h>
 #include <pthread.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -23,6 +24,8 @@ smokey_test_plugin(xddp,
 
 static pthread_t rt1, rt2, nrt;
 
+static sem_t semsync;
+
 #define XDDP_PORT_LABEL  "xddp-smokey"
 
 static void fail(const char *reason)
@@ -59,6 +62,7 @@ static void *realtime_thread1(void *arg)
 
        FD_ZERO(&set);
        FD_SET(s, &set);
+       sem_post(&semsync); /* unleash client RT thread */
 
        for (;;) {
                control++;
@@ -89,6 +93,19 @@ static void *realtime_thread1(void *arg)
        return NULL;
 }
 
+static void sem_sync(sem_t *sem)
+{
+       int ret;
+
+       for (;;) {
+               ret = sem_wait(sem);
+               if (ret == 0)
+                       return;
+               if (errno != EINTR)
+                       fail("sem_wait");
+       }
+}
+
 static void *realtime_thread2(void *arg)
 {
        struct rtipc_port_label plabel;
@@ -119,6 +136,9 @@ static void *realtime_thread2(void *arg)
        if (ret)
                fail("setsockopt");
 
+       sem_sync(&semsync);
+       sem_post(&semsync); /* unleash regular thread */
+
        memset(&saddr, 0, sizeof(saddr));
        saddr.sipc_family = AF_RTIPC;
        saddr.sipc_port = -1;   /* Tell XDDP to search by label. */
@@ -200,6 +220,8 @@ static int run_xddp(struct smokey_test *t, int argc, char 
*const argv[])
        struct sched_param param = { .sched_priority = 42 };
        pthread_attr_t rtattr, regattr;
 
+       sem_init(&semsync, 0, 0);
+
        pthread_attr_init(&rtattr);
        pthread_attr_setdetachstate(&rtattr, PTHREAD_CREATE_JOINABLE);
        pthread_attr_setinheritsched(&rtattr, PTHREAD_EXPLICIT_SCHED);


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

Reply via email to