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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Apr  7 21:10:09 2013 +0200

regression: use a semaphore to enforce synchronization

---

 src/testsuite/regression/posix/xddp_test.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/testsuite/regression/posix/xddp_test.c 
b/src/testsuite/regression/posix/xddp_test.c
index df87a4e..194584e 100644
--- a/src/testsuite/regression/posix/xddp_test.c
+++ b/src/testsuite/regression/posix/xddp_test.c
@@ -5,21 +5,23 @@
  *
  * This test causes a crash with Xenomai 2.6.1 and earlier versions.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
 #include <string.h>
-#include <malloc.h>
-#include <pthread.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <rtdk.h>
+
+#include <unistd.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include <pthread.h>
+#include <semaphore.h>
+
 #include <rtdm/rtipc.h>
 #include "check.h"
 
 static pthread_t rt, nrt;
+static sem_t opened;
 
 #define XDDP_PORT 0    /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] */
 
@@ -73,9 +75,12 @@ static void *realtime_thread(void *arg)
                exit(EXIT_FAILURE);
        }
 
+       check_unix(sem_post(&opened));
        ts.tv_sec = 0;
        ts.tv_nsec = 500000000; /* 500 ms */
        check_unix(clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL));
+       check_unix(sem_wait(&opened));
+       check_unix(sem_destroy(&opened));
        check_unix(close(s));
 
        return NULL;
@@ -90,6 +95,7 @@ static void *regular_thread(void *arg)
 
        fd = check_unix(open(devname, O_RDWR));
        free(devname);
+       check_unix(sem_post(&opened));
 
        for (;;) {
                /* Get the next message from realtime_thread. */
@@ -128,6 +134,7 @@ int main(int argc, char **argv)
        check_unix(signal(SIGHUP, cleanup_upon_sig) == SIG_ERR ? -1 : 0);
        check_pthread(pthread_sigmask(SIG_BLOCK, &mask, &oldmask));
 
+       check_unix(sem_init(&opened, 0, 0));
        check_pthread(pthread_attr_init(&rtattr));
        check_pthread(pthread_attr_setdetachstate(&rtattr,
                                                  PTHREAD_CREATE_JOINABLE));
@@ -138,6 +145,7 @@ int main(int argc, char **argv)
 
        check_pthread(pthread_create(&rt, &rtattr, &realtime_thread, NULL));
        check_pthread(pthread_attr_destroy(&rtattr));
+       check_unix(sem_wait(&opened));
 
        check_pthread(pthread_attr_init(&regattr));
        check_pthread(pthread_attr_setdetachstate(&regattr,


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

Reply via email to