diff options
Diffstat (limited to 'nuttx/examples/ostest/timedwait.c')
-rw-r--r-- | nuttx/examples/ostest/timedwait.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/nuttx/examples/ostest/timedwait.c b/nuttx/examples/ostest/timedwait.c index b01b352ff..af2fd2551 100644 --- a/nuttx/examples/ostest/timedwait.c +++ b/nuttx/examples/ostest/timedwait.c @@ -37,6 +37,7 @@ #include <time.h> #include <pthread.h> #include <unistd.h> +#include <errno.h> #include "ostest.h" static pthread_mutex_t mutex; @@ -70,7 +71,18 @@ static void *thread_waiter(void *parameter) status = pthread_cond_timedwait(&cond, &mutex, &time); if (status != 0) { - printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status); + if (status == ETIMEDOUT) + { + printf("thread_waiter: pthread_cond_timedwait timed out\n"); + } + else + { + printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status); + } + } + else + { + printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, status=%d\n", status); } /* Release the mutex */ @@ -102,32 +114,32 @@ void timedwait_test(void) status = pthread_mutex_init(&mutex, NULL); if (status != 0) { - printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_mutex_init failed, status=%d\n", status); } /* Initialize the condition variable */ - printf("timedwait_test: Initializing cond\n"); + printf("timedwait_test: Initializing cond\n"); status = pthread_cond_init(&cond, NULL); if (status != 0) { - printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_condinit failed, status=%d\n", status); } /* Start the waiter thread at higher priority */ - printf("timedwait_test: Starting waiter\n"); + printf("timedwait_test: Starting waiter\n"); status = pthread_attr_init(&attr); if (status != 0) { - printf("timedwait_test: pthread_attr_init failed, status=%d\n", status); + printf("timedwait_test: pthread_attr_init failed, status=%d\n", status); } prio_max = sched_get_priority_max(SCHED_FIFO); status = sched_getparam (getpid(), &sparam); if (status != 0) { - printf("timedwait_test: sched_getparam failed\n"); + printf("timedwait_test: sched_getparam failed\n"); sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY; } @@ -135,27 +147,27 @@ void timedwait_test(void) status = pthread_attr_setschedparam(&attr,&sparam); if (status != OK) { - printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status); + printf("timedwait_test: pthread_attr_setschedparam failed, status=%d\n", status); } else { - printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority); + printf("timedwait_test: Set thread 2 priority to %d\n", sparam.sched_priority); } status = pthread_create(&waiter, &attr, thread_waiter, NULL); if (status != 0) { - printf("timedwait_test: pthread_create failed, status=%d\n", status); + printf("timedwait_test: pthread_create failed, status=%d\n", status); } - printf("timedwait_test: Joining\n"); + printf("timedwait_test: Joining\n"); status = pthread_join(waiter, &result); if (status != 0) { - printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status); + printf("timedwait_test: ERROR pthread_join failed, status=%d\n", status); } else { - printf("timedwait_test: waiter exited with result=%p\n", result); + printf("timedwait_test: waiter exited with result=%p\n", result); } } |