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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Aug 13 16:11:09 2014 +0200

demo/posix: sanitize RTIPC examples

---

 demo/posix/cobalt/bufp-label.c     |   83 +++++++++++++-------------------
 demo/posix/cobalt/bufp-readwrite.c |   83 +++++++++++++-------------------
 demo/posix/cobalt/iddp-label.c     |   49 ++++++-------------
 demo/posix/cobalt/iddp-sendrecv.c  |   83 +++++++++++++-------------------
 demo/posix/cobalt/xddp-echo.c      |   85 ++++++++++++--------------------
 demo/posix/cobalt/xddp-label.c     |   93 ++++++++++++++----------------------
 demo/posix/cobalt/xddp-stream.c    |   85 ++++++++++++--------------------
 7 files changed, 208 insertions(+), 353 deletions(-)

diff --git a/demo/posix/cobalt/bufp-label.c b/demo/posix/cobalt/bufp-label.c
index aa41ee7..09cd549 100644
--- a/demo/posix/cobalt/bufp-label.c
+++ b/demo/posix/cobalt/bufp-label.c
@@ -5,10 +5,7 @@
  * In this example, two sockets are created.  A server thread (reader)
  * is bound to a real-time port and receives a stream of bytes sent to
  * this port from a client thread (writer).
- *
- * See Makefile in this directory for build directives.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -23,22 +20,22 @@ pthread_t svtid, cltid;
 #define BUFP_PORT_LABEL  "bufp-demo"
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -102,8 +99,8 @@ static void *server(void *arg)
                        close(s);
                        fail("read");
                }
-               rt_printf("%s: received %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, buf);
+               printf("%s: received %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, buf);
        }
 
        return NULL;
@@ -147,8 +144,8 @@ static void *client(void *arg)
                        close(s);
                        fail("write");
                }
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
                 * We run in full real-time mode (i.e. primary mode),
@@ -163,39 +160,19 @@ static void *client(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(svtid);
-       pthread_cancel(cltid);
-       signal(sig, SIG_DFL);
-       pthread_join(svtid, NULL);
-       pthread_join(cltid, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param svparam = {.sched_priority = 71 };
        struct sched_param clparam = {.sched_priority = 70 };
        pthread_attr_t svattr, clattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary mode.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&svattr);
        pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
@@ -217,7 +194,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(svtid);
+       pthread_cancel(cltid);
+       pthread_join(svtid, NULL);
+       pthread_join(cltid, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/bufp-readwrite.c 
b/demo/posix/cobalt/bufp-readwrite.c
index fe8b136..a79a0d4 100644
--- a/demo/posix/cobalt/bufp-readwrite.c
+++ b/demo/posix/cobalt/bufp-readwrite.c
@@ -5,10 +5,7 @@
  * In this example, two sockets are created.  A server thread (reader)
  * is bound to a real-time port and receives a stream of bytes sent to
  * this port from a client thread (writer).
- *
- * See Makefile in this directory for build directives.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -23,22 +20,22 @@ pthread_t svtid, cltid;
 #define BUFP_SVPORT 12
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -81,8 +78,8 @@ static void *server(void *arg)
                        close(s);
                        fail("read");
                }
-               rt_printf("%s: received %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, buf);
+               printf("%s: received %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, buf);
        }
 
        return NULL;
@@ -112,8 +109,8 @@ static void *client(void *arg)
                        close(s);
                        fail("write");
                }
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
                 * We run in full real-time mode (i.e. primary mode),
@@ -128,39 +125,19 @@ static void *client(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(svtid);
-       pthread_cancel(cltid);
-       signal(sig, SIG_DFL);
-       pthread_join(svtid, NULL);
-       pthread_join(cltid, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param svparam = {.sched_priority = 71 };
        struct sched_param clparam = {.sched_priority = 70 };
        pthread_attr_t svattr, clattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary mode.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&svattr);
        pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
@@ -182,7 +159,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(svtid);
+       pthread_cancel(cltid);
+       pthread_join(svtid, NULL);
+       pthread_join(cltid, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/iddp-label.c b/demo/posix/cobalt/iddp-label.c
index 66b9b1e..519f169 100644
--- a/demo/posix/cobalt/iddp-label.c
+++ b/demo/posix/cobalt/iddp-label.c
@@ -12,10 +12,7 @@
  * ASCII labels can be attached to bound ports, in order to connect
  * sockets to them in a more descriptive way than using plain numeric
  * port values.
- *
- * See Makefile in this directory for build directives.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -107,7 +104,7 @@ static void *server(void *arg)
                        close(s);
                        fail("recvfrom");
                }
-               rt_printf("%s: received %d bytes, \"%.*s\" from port %d\n",
+               printf("%s: received %d bytes, \"%.*s\" from port %d\n",
                          __FUNCTION__, ret, ret, buf, claddr.sipc_port);
        }
 
@@ -164,8 +161,8 @@ static void *client(void *arg)
                        close(s);
                        fail("sendto");
                }
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
                 * We run in full real-time mode (i.e. primary mode),
@@ -180,39 +177,19 @@ static void *client(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(svtid);
-       pthread_cancel(cltid);
-       signal(sig, SIG_DFL);
-       pthread_join(svtid, NULL);
-       pthread_join(cltid, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param svparam = {.sched_priority = 71 };
        struct sched_param clparam = {.sched_priority = 70 };
        pthread_attr_t svattr, clattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary mode.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&svattr);
        pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
@@ -234,7 +211,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(svtid);
+       pthread_cancel(cltid);
+       pthread_join(svtid, NULL);
+       pthread_join(cltid, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/iddp-sendrecv.c 
b/demo/posix/cobalt/iddp-sendrecv.c
index cee62bf..eda48a2 100644
--- a/demo/posix/cobalt/iddp-sendrecv.c
+++ b/demo/posix/cobalt/iddp-sendrecv.c
@@ -7,10 +7,7 @@
  * port from a client thread (writer). The client socket is bound to a
  * different port, only to provide a valid peer name; this is
  * optional.
- *
- * See Makefile in this directory for build directives.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -26,22 +23,22 @@ pthread_t svtid, cltid;
 #define IDDP_CLPORT 13
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -87,8 +84,8 @@ static void *server(void *arg)
                        close(s);
                        fail("recvfrom");
                }
-               rt_printf("%s: received %d bytes, \"%.*s\" from port %d\n",
-                         __FUNCTION__, ret, ret, buf, claddr.sipc_port);
+               printf("%s: received %d bytes, \"%.*s\" from port %d\n",
+                      __FUNCTION__, ret, ret, buf, claddr.sipc_port);
        }
 
        return NULL;
@@ -120,8 +117,8 @@ static void *client(void *arg)
                        close(s);
                        fail("sendto");
                }
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
                 * We run in full real-time mode (i.e. primary mode),
@@ -136,39 +133,19 @@ static void *client(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(svtid);
-       pthread_cancel(cltid);
-       signal(sig, SIG_DFL);
-       pthread_join(svtid, NULL);
-       pthread_join(cltid, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param svparam = {.sched_priority = 71 };
        struct sched_param clparam = {.sched_priority = 70 };
        pthread_attr_t svattr, clattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary mode.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&svattr);
        pthread_attr_setdetachstate(&svattr, PTHREAD_CREATE_JOINABLE);
@@ -190,7 +167,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(svtid);
+       pthread_cancel(cltid);
+       pthread_join(svtid, NULL);
+       pthread_join(cltid, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/xddp-echo.c b/demo/posix/cobalt/xddp-echo.c
index 552927e..cf16bb0 100644
--- a/demo/posix/cobalt/xddp-echo.c
+++ b/demo/posix/cobalt/xddp-echo.c
@@ -39,13 +39,7 @@
  *   =>  open /dev/rtp0                                 |  ^
  *   =>  read traffic from RT domain via read()         |  |
  *   =>  echo traffic back to RT domain via write()     +--+
- *
- * See Makefile in this directory for build directives.
- *
- * NOTE: XDDP is a replacement for the legacy RT_PIPE interface
- * available from the native skin until Xenomai 3.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -62,22 +56,22 @@ pthread_t rt, nrt;
 #define XDDP_PORT 0    /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] */
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -143,15 +137,15 @@ static void *realtime_thread(void *arg)
                if (ret != len)
                        fail("sendto");
 
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
 
                /* Read back packets echoed by the regular thread */
                ret = recvfrom(s, buf, sizeof(buf), 0, NULL, 0);
                if (ret <= 0)
                        fail("recvfrom");
 
-               rt_printf("   => \"%.*s\" echoed by peer\n", ret, buf);
+               printf("   => \"%.*s\" echoed by peer\n", ret, buf);
 
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
@@ -195,39 +189,18 @@ static void *regular_thread(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(rt);
-       pthread_cancel(nrt);
-       signal(sig, SIG_DFL);
-       pthread_join(rt, NULL);
-       pthread_join(nrt, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param rtparam = { .sched_priority = 42 };
        pthread_attr_t rtattr, regattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary (i.e. non real-time) mode when
-        * writing output.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&rtattr);
        pthread_attr_setdetachstate(&rtattr, PTHREAD_CREATE_JOINABLE);
@@ -248,7 +221,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(rt);
+       pthread_cancel(nrt);
+       pthread_join(rt, NULL);
+       pthread_join(nrt, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/xddp-label.c b/demo/posix/cobalt/xddp-label.c
index e141ff8..6e3c364 100644
--- a/demo/posix/cobalt/xddp-label.c
+++ b/demo/posix/cobalt/xddp-label.c
@@ -45,13 +45,7 @@
  *   =>  open /proc/xenomai/registry/rtipc/xddp/xddp-demo  |  |
  *   =>  read traffic from RT domain via read()            |  |
  *   =>  mirror traffic to RT domain via write()           +--+
- *
- * See Makefile in this directory for build directives.
- *
- * NOTE: XDDP is a replacement for the legacy RT_PIPE interface
- * available from the native skin until Xenomai 3.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -68,22 +62,22 @@ pthread_t rt1, rt2, nrt;
 #define XDDP_PORT_LABEL  "xddp-demo"
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -144,7 +138,7 @@ static void *realtime_thread1(void *arg)
                if (ret <= 0)
                        fail("recvfrom");
 
-               rt_printf("%s: \"%.*s\" relayed by peer\n", __FUNCTION__, ret, 
buf);
+               printf("%s: \"%.*s\" relayed by peer\n", __FUNCTION__, ret, 
buf);
        }
 
        return NULL;
@@ -206,8 +200,8 @@ static void *realtime_thread2(void *arg)
        if (ret || addrlen != sizeof(saddr))
                fail("getpeername");
 
-       rt_printf("%s: NRT peer is reading from /dev/rtp%d\n",
-                 __FUNCTION__, saddr.sipc_port);
+       printf("%s: NRT peer is reading from /dev/rtp%d\n",
+              __FUNCTION__, saddr.sipc_port);
 
        for (;;) {
                len = strlen(msg[n]);
@@ -221,8 +215,8 @@ static void *realtime_thread2(void *arg)
                if (ret != len)
                        fail("sendto");
 
-               rt_printf("%s: sent %d bytes, \"%.*s\"\n",
-                         __FUNCTION__, ret, ret, msg[n]);
+               printf("%s: sent %d bytes, \"%.*s\"\n",
+                      __FUNCTION__, ret, ret, msg[n]);
 
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
@@ -268,41 +262,18 @@ static void *regular_thread(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(rt1);
-       pthread_cancel(rt2);
-       pthread_cancel(nrt);
-       signal(sig, SIG_DFL);
-       pthread_join(rt1, NULL);
-       pthread_join(rt2, NULL);
-       pthread_join(nrt, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param rtparam = { .sched_priority = 42 };
        pthread_attr_t rtattr, regattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary (i.e. non real-time) mode when
-        * writing output.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&rtattr);
        pthread_attr_setdetachstate(&rtattr, PTHREAD_CREATE_JOINABLE);
@@ -329,7 +300,13 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(rt1);
+       pthread_cancel(rt2);
+       pthread_cancel(nrt);
+       pthread_join(rt1, NULL);
+       pthread_join(rt2, NULL);
+       pthread_join(nrt, NULL);
 
        return 0;
 }
diff --git a/demo/posix/cobalt/xddp-stream.c b/demo/posix/cobalt/xddp-stream.c
index 8736fab..c392747 100644
--- a/demo/posix/cobalt/xddp-stream.c
+++ b/demo/posix/cobalt/xddp-stream.c
@@ -41,13 +41,7 @@
  *   =>  open /dev/rtp0                                            |  ^
  *   =>  read traffic from RT domain via read()                    |  |
  *   =>  echo traffic back to RT domain via write()                +--+
- *
- * See Makefile in this directory for build directives.
- *
- * NOTE: XDDP is a replacement for the legacy RT_PIPE interface
- * available from the native skin until Xenomai 3.
  */
-#include <sys/mman.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -64,22 +58,22 @@ pthread_t rt, nrt;
 #define XDDP_PORT 0    /* [0..CONFIG-XENO_OPT_PIPE_NRDEV - 1] */
 
 static const char *msg[] = {
-    "Surfing With The Alien",
-    "Lords of Karma",
-    "Banana Mango",
-    "Psycho Monkey",
-    "Luminous Flesh Giants",
-    "Moroccan Sunset",
-    "Satch Boogie",
-    "Flying In A Blue Dream",
-    "Ride",
-    "Summer Song",
-    "Speed Of Light",
-    "Crystal Planet",
-    "Raspberry Jam Delta-V",
-    "Champagne?",
-    "Clouds Race Across The Sky",
-    "Engines Of Creation"
+       "Surfing With The Alien",
+       "Lords of Karma",
+       "Banana Mango",
+       "Psycho Monkey",
+       "Luminous Flesh Giants",
+       "Moroccan Sunset",
+       "Satch Boogie",
+       "Flying In A Blue Dream",
+       "Ride",
+       "Summer Song",
+       "Speed Of Light",
+       "Crystal Planet",
+       "Raspberry Jam Delta-V",
+       "Champagne?",
+       "Clouds Race Across The Sky",
+       "Engines Of Creation"
 };
 
 static void fail(const char *reason)
@@ -149,15 +143,15 @@ static void *realtime_thread(void *arg)
                                fail("sendto");
                }
 
-               rt_printf("%s: sent (scattered) %d-bytes message, \"%.*s\"\n",
-                         __FUNCTION__, len, len, msg[n]);
+               printf("%s: sent (scattered) %d-bytes message, \"%.*s\"\n",
+                      __FUNCTION__, len, len, msg[n]);
 
                /* Read back packets echoed by the regular thread */
                ret = recvfrom(s, buf, sizeof(buf), 0, NULL, 0);
                if (ret <= 0)
                        fail("recvfrom");
 
-               rt_printf("   => \"%.*s\" echoed by peer\n", ret, buf);
+               printf("   => \"%.*s\" echoed by peer\n", ret, buf);
 
                n = (n + 1) % (sizeof(msg) / sizeof(msg[0]));
                /*
@@ -201,39 +195,18 @@ static void *regular_thread(void *arg)
        return NULL;
 }
 
-static void cleanup_upon_sig(int sig)
-{
-       pthread_cancel(rt);
-       pthread_cancel(nrt);
-       signal(sig, SIG_DFL);
-       pthread_join(rt, NULL);
-       pthread_join(nrt, NULL);
-}
-
 int main(int argc, char **argv)
 {
        struct sched_param rtparam = { .sched_priority = 42 };
        pthread_attr_t rtattr, regattr;
-       sigset_t mask, oldmask;
+       sigset_t set;
+       int sig;
 
-       mlockall(MCL_CURRENT | MCL_FUTURE);
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGINT);
-       signal(SIGINT, cleanup_upon_sig);
-       sigaddset(&mask, SIGTERM);
-       signal(SIGTERM, cleanup_upon_sig);
-       sigaddset(&mask, SIGHUP);
-       signal(SIGHUP, cleanup_upon_sig);
-       pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
-
-       /*
-        * This is a real-time compatible printf() package from
-        * Xenomai's RT Development Kit (RTDK), that does NOT cause
-        * any transition to secondary (i.e. non real-time) mode when
-        * writing output.
-        */
-       rt_print_auto_init(1);
+       sigemptyset(&set);
+       sigaddset(&set, SIGINT);
+       sigaddset(&set, SIGTERM);
+       sigaddset(&set, SIGHUP);
+       pthread_sigmask(SIG_BLOCK, &set, NULL);
 
        pthread_attr_init(&rtattr);
        pthread_attr_setdetachstate(&rtattr, PTHREAD_CREATE_JOINABLE);
@@ -254,7 +227,11 @@ int main(int argc, char **argv)
        if (errno)
                fail("pthread_create");
 
-       sigsuspend(&oldmask);
+       sigwait(&set, &sig);
+       pthread_cancel(rt);
+       pthread_cancel(nrt);
+       pthread_join(rt, NULL);
+       pthread_join(nrt, NULL);
 
        return 0;
 }


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

Reply via email to