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
This commit is contained in:
parent
8d7952d55a
commit
1d369fb376
@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* apps/examples/ostest/semtimed.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -92,6 +92,7 @@ void semtimed_test(void)
|
|||||||
int prio_min;
|
int prio_min;
|
||||||
int prio_max;
|
int prio_max;
|
||||||
int prio_mid;
|
int prio_mid;
|
||||||
|
int errcode;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -106,7 +107,9 @@ void semtimed_test(void)
|
|||||||
abstime.tv_nsec = before.tv_nsec;
|
abstime.tv_nsec = before.tv_nsec;
|
||||||
|
|
||||||
printf("semtimed_test: Waiting for two second timeout\n");
|
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);
|
(void)clock_gettime(CLOCK_REALTIME, &after);
|
||||||
|
|
||||||
if (status == OK)
|
if (status == OK)
|
||||||
@ -115,7 +118,6 @@ void semtimed_test(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
|
||||||
if (errcode == ETIMEDOUT)
|
if (errcode == ETIMEDOUT)
|
||||||
{
|
{
|
||||||
printf("samwait_test: PASS\n");
|
printf("samwait_test: PASS\n");
|
||||||
@ -192,12 +194,13 @@ void semtimed_test(void)
|
|||||||
abstime.tv_nsec = before.tv_nsec;
|
abstime.tv_nsec = before.tv_nsec;
|
||||||
|
|
||||||
printf("semtimed_test: Waiting for two second timeout\n");
|
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);
|
(void)clock_gettime(CLOCK_REALTIME, &after);
|
||||||
|
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
|
||||||
printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode);
|
printf("semtimed_test: ERROR: sem_timedwait failed with: %d\n", errcode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user