[rtems commit] posix: Fix use of clock for relative times
Sebastian Huber
sebh at rtems.org
Tue May 18 18:32:35 UTC 2021
Module: rtems
Branch: master
Commit: 24c6293294916e0224278854f73434205aa5d0c8
Changeset: http://git.rtems.org/rtems/commit/?id=24c6293294916e0224278854f73434205aa5d0c8
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Tue May 18 11:28:08 2021 +0200
posix: Fix use of clock for relative times
Close #4426.
---
cpukit/posix/src/clocknanosleep.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/cpukit/posix/src/clocknanosleep.c b/cpukit/posix/src/clocknanosleep.c
index 951268bc..588f67a 100644
--- a/cpukit/posix/src/clocknanosleep.c
+++ b/cpukit/posix/src/clocknanosleep.c
@@ -44,7 +44,7 @@ int clock_nanosleep(
)
{
Thread_queue_Context queue_context;
- struct timespec uptime;
+ struct timespec now;
const struct timespec *end;
Thread_Control *executing;
int eno;
@@ -61,21 +61,22 @@ int clock_nanosleep(
if ( ( flags & TIMER_ABSTIME ) != 0 ) {
end = rqtp;
-
+ } else {
if ( clock_id == CLOCK_REALTIME ) {
- _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
- &queue_context,
- end
- );
+ _Timecounter_Nanotime( &now );
} else {
- _Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
- &queue_context,
- end
- );
+ _Timecounter_Nanouptime( &now );
}
+
+ end = _Watchdog_Future_timespec( &now, rqtp );
+ }
+
+ if ( clock_id == CLOCK_REALTIME ) {
+ _Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
+ &queue_context,
+ end
+ );
} else {
- _Timecounter_Nanouptime( &uptime );
- end = _Watchdog_Future_timespec( &uptime, rqtp );
_Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
&queue_context,
end
@@ -101,7 +102,11 @@ int clock_nanosleep(
if ( eno == EINTR ) {
struct timespec actual_end;
- _Timecounter_Nanouptime( &actual_end );
+ if ( clock_id == CLOCK_REALTIME ) {
+ _Timecounter_Nanotime( &actual_end );
+ } else {
+ _Timecounter_Nanouptime( &actual_end );
+ }
if ( _Timespec_Less_than( &actual_end, end ) ) {
_Timespec_Subtract( &actual_end, end, rmtp );
More information about the vc
mailing list