summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-19 08:41:15 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-19 08:41:15 -0600
commit406c3a3b7ddefbfadbae9ac1858a4b235c7e6cfd (patch)
tree6727ef6251a1bd8ce38e99da234c0c0a8985cf59
parentef6882ab743f7286d168ca10cc16dc6b72caf7cf (diff)
downloadnuttx-406c3a3b7ddefbfadbae9ac1858a4b235c7e6cfd.tar.gz
nuttx-406c3a3b7ddefbfadbae9ac1858a4b235c7e6cfd.tar.bz2
nuttx-406c3a3b7ddefbfadbae9ac1858a4b235c7e6cfd.zip
apps/examples/ostest: Sample errno on returns from sem_timedwait(). Otherwise, intervening system calls my change the value of the reported errno. Noted by Juha Niskanen
-rw-r--r--apps/examples/ostest/semtimed.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/apps/examples/ostest/semtimed.c b/apps/examples/ostest/semtimed.c
index 447f97cc5..fc147aa06 100644
--- a/apps/examples/ostest/semtimed.c
+++ b/apps/examples/ostest/semtimed.c
@@ -1,7 +1,7 @@
/***********************************************************************
* apps/examples/ostest/semtimed.c
*
- * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -92,6 +92,7 @@ void semtimed_test(void)
int prio_min;
int prio_max;
int prio_mid;
+ int errcode;
pthread_attr_t attr;
int status;
@@ -106,7 +107,9 @@ void semtimed_test(void)
abstime.tv_nsec = before.tv_nsec;
printf("semtimed_test: Waiting for two second timeout\n");
- status = sem_timedwait(&sem, &abstime);
+ status = sem_timedwait(&sem, &abstime);
+ errcode = errno;
+
(void)clock_gettime(CLOCK_REALTIME, &after);
if (status == OK)
@@ -115,7 +118,6 @@ void semtimed_test(void)
}
else
{
- int errcode = errno;
if (errcode == ETIMEDOUT)
{
printf("samwait_test: PASS\n");
@@ -192,12 +194,13 @@ void semtimed_test(void)
abstime.tv_nsec = before.tv_nsec;
printf("semtimed_test: Waiting for two second timeout\n");
- status = sem_timedwait(&sem, &abstime);
+ status = sem_timedwait(&sem, &abstime);
+ errcode = errno;
+
(void)clock_gettime(CLOCK_REALTIME, &after);
if (status < 0)
{
- int errcode = errno;
printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode);
}
else