diff options
Diffstat (limited to 'nuttx/examples/ostest')
-rw-r--r-- | nuttx/examples/ostest/posixtimer.c | 34 | ||||
-rw-r--r-- | nuttx/examples/ostest/timedmqueue.c | 10 | ||||
-rw-r--r-- | nuttx/examples/ostest/timedwait.c | 35 |
3 files changed, 69 insertions, 10 deletions
diff --git a/nuttx/examples/ostest/posixtimer.c b/nuttx/examples/ostest/posixtimer.c index 1b466c99f..87498baa2 100644 --- a/nuttx/examples/ostest/posixtimer.c +++ b/nuttx/examples/ostest/posixtimer.c @@ -1,7 +1,7 @@ /*********************************************************************** * posixtimer.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,6 +33,10 @@ * ***********************************************************************/ +/************************************************************************** + * Included Files + **************************************************************************/ + #include <sys/types.h> #include <stdio.h> #include <unistd.h> @@ -42,6 +46,10 @@ #include <errno.h> #include "ostest.h" +/************************************************************************** + * Private Definitions + **************************************************************************/ + #ifndef NULL # define NULL (void*)0 #endif @@ -49,9 +57,23 @@ #define MY_TIMER_SIGNAL 17 #define SIGVALUE_INT 42 +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 +# define FFLUSH() fflush(stdout) +#else +# define FFLUSH() +#endif + +/************************************************************************** + * Private Data + **************************************************************************/ + static sem_t sem; static int g_nsigreceived = 0; +/************************************************************************** + * Private Functions + **************************************************************************/ + static void timer_expiration(int signo, siginfo_t *info, void *ucontext) { sigset_t oldset; @@ -119,6 +141,10 @@ static void timer_expiration(int signo, siginfo_t *info, void *ucontext) } +/************************************************************************** + * Public Functions + **************************************************************************/ + void timer_test(void) { sigset_t sigset; @@ -200,7 +226,7 @@ void timer_test(void) for (i = 0; i < 5; i++) { printf("timer_test: Waiting on semaphore\n" ); - fflush(stdout); + FFLUSH(); status = sem_wait(&sem); if (status != 0) { @@ -239,5 +265,5 @@ errorout: status = sigaction(MY_TIMER_SIGNAL, &act, &oact); printf("timer_test: done\n" ); - fflush(stdout); + FFLUSH(); } diff --git a/nuttx/examples/ostest/timedmqueue.c b/nuttx/examples/ostest/timedmqueue.c index 186296a06..2ef0dedea 100644 --- a/nuttx/examples/ostest/timedmqueue.c +++ b/nuttx/examples/ostest/timedmqueue.c @@ -66,6 +66,12 @@ #define TEST_SEND_NMSGS (10) #define TEST_RECEIVE_NMSGS (10) +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 +# define FFLUSH() fflush(stdout) +#else +# define FFLUSH() +#endif + /************************************************************************** * Private Types **************************************************************************/ @@ -180,7 +186,7 @@ static void *sender_thread(void *arg) } printf("sender_thread: returning nerrors=%d\n", nerrors); - fflush(stdout); + FFLUSH(); return (pthread_addr_t)nerrors; } @@ -305,7 +311,7 @@ static void *receiver_thread(void *arg) } printf("receiver_thread: returning nerrors=%d\n", nerrors); - fflush(stdout); + FFLUSH(); pthread_exit((pthread_addr_t)nerrors); return (pthread_addr_t)nerrors; } diff --git a/nuttx/examples/ostest/timedwait.c b/nuttx/examples/ostest/timedwait.c index 0bc47c693..51622bad8 100644 --- a/nuttx/examples/ostest/timedwait.c +++ b/nuttx/examples/ostest/timedwait.c @@ -1,7 +1,7 @@ /*********************************************************************** - * timedwait.c + * examples/ostest/timedwait.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -33,16 +33,39 @@ * ***********************************************************************/ +/************************************************************************** + * Included Files + **************************************************************************/ + #include <stdio.h> #include <time.h> #include <pthread.h> #include <unistd.h> #include <errno.h> + #include "ostest.h" +/************************************************************************** + * Private Definitions + **************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 +# define FFLUSH() fflush(stdout) +#else +# define FFLUSH() +#endif + +/************************************************************************** + * Private Data + **************************************************************************/ + static pthread_mutex_t mutex; static pthread_cond_t cond; +/************************************************************************** + * Private Functions + **************************************************************************/ + static void *thread_waiter(void *parameter) { struct timespec time; @@ -99,6 +122,10 @@ static void *thread_waiter(void *parameter) return NULL; } +/************************************************************************** + * Public Definitions + **************************************************************************/ + void timedwait_test(void) { pthread_t waiter; @@ -161,7 +188,7 @@ void timedwait_test(void) } printf("timedwait_test: Joining\n"); - fflush(stdout); + FFLUSH(); status = pthread_join(waiter, &result); if (status != 0) { |