From a1bfb335c0cc274513e144da46e203bff29e000b Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 1 Sep 2011 18:24:57 +0000 Subject: 2011-09-01 Joel Sherrill PR 1895/cpukit * posix/src/mqueuerecvsupp.c, posix/src/pthreadjoin.c, score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c, score/src/timespectoticks.c: Ensure time conversions to ticks do not ignore partial tick and return 1 less than desired. --- cpukit/ChangeLog | 8 ++++++++ cpukit/posix/src/mqueuerecvsupp.c | 9 ++++++--- cpukit/posix/src/pthreadjoin.c | 21 +++++++++++---------- cpukit/score/src/coretodmsecstoticks.c | 17 +++++++++++++++-- cpukit/score/src/coretodusectoticks.c | 17 +++++++++++++++-- cpukit/score/src/timespectoticks.c | 18 ++++++++++++------ 6 files changed, 67 insertions(+), 23 deletions(-) (limited to 'cpukit') diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 7cd189174a..7ba750ce9b 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,11 @@ +2011-09-01 Joel Sherrill + + PR 1895/cpukit + * posix/src/mqueuerecvsupp.c, posix/src/pthreadjoin.c, + score/src/coretodmsecstoticks.c, score/src/coretodusectoticks.c, + score/src/timespectoticks.c: Ensure time conversions to ticks do not + ignore partial tick and return 1 less than desired. + 2011-07-31 Joel Sherrill PR 1855/cpukit diff --git a/cpukit/posix/src/mqueuerecvsupp.c b/cpukit/posix/src/mqueuerecvsupp.c index 9c3fb47371..717fef8c9d 100644 --- a/cpukit/posix/src/mqueuerecvsupp.c +++ b/cpukit/posix/src/mqueuerecvsupp.c @@ -11,7 +11,7 @@ * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open * time. * - * COPYRIGHT (c) 1989-2008. + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -105,8 +105,11 @@ ssize_t _POSIX_Message_queue_Receive_support( ); _Thread_Enable_dispatch(); - *msg_prio = - _POSIX_Message_queue_Priority_from_core(_Thread_Executing->Wait.count); + if (msg_prio) { + *msg_prio = _POSIX_Message_queue_Priority_from_core( + _Thread_Executing->Wait.count + ); + } if ( !_Thread_Executing->Wait.return_code ) return length_out; diff --git a/cpukit/posix/src/pthreadjoin.c b/cpukit/posix/src/pthreadjoin.c index 0b7e103614..38f2389ea4 100644 --- a/cpukit/posix/src/pthreadjoin.c +++ b/cpukit/posix/src/pthreadjoin.c @@ -55,20 +55,21 @@ on_EINTR: if ( the_thread->current_state == (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) ) { - return_pointer = the_thread->Wait.return_argument; - _Thread_Clear_state( - the_thread, - (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) - ); + return_pointer = the_thread->Wait.return_argument; + _Thread_Clear_state( + the_thread, + (STATES_WAITING_FOR_JOIN_AT_EXIT | STATES_TRANSIENT) + ); + _Thread_Enable_dispatch(); } else { - _Thread_Executing->Wait.return_argument = &return_pointer; + _Thread_Executing->Wait.return_argument = &return_pointer; _Thread_queue_Enter_critical_section( &api->Join_List ); _Thread_queue_Enqueue( &api->Join_List, WATCHDOG_NO_TIMEOUT ); - } - _Thread_Enable_dispatch(); + _Thread_Enable_dispatch(); - if ( _Thread_Executing->Wait.return_code == EINTR ) - goto on_EINTR; + if ( _Thread_Executing->Wait.return_code == EINTR ) + goto on_EINTR; + } if ( value_ptr ) *value_ptr = return_pointer; diff --git a/cpukit/score/src/coretodmsecstoticks.c b/cpukit/score/src/coretodmsecstoticks.c index cddd3d646d..0b6fa6dede 100644 --- a/cpukit/score/src/coretodmsecstoticks.c +++ b/cpukit/score/src/coretodmsecstoticks.c @@ -1,4 +1,4 @@ -/* COPYRIGHT (c) 1989-2008. +/* COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -21,5 +21,18 @@ uint32_t TOD_MILLISECONDS_TO_TICKS( uint32_t milliseconds ) { - return (milliseconds / rtems_configuration_get_milliseconds_per_tick()); + uint32_t ticks; + uint32_t milliseconds_per_tick; + + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + milliseconds_per_tick = rtems_configuration_get_milliseconds_per_tick(); + ticks = milliseconds / milliseconds_per_tick; + if ( (milliseconds % milliseconds_per_tick) != 0 ) + ticks += 1; + + return ticks; } diff --git a/cpukit/score/src/coretodusectoticks.c b/cpukit/score/src/coretodusectoticks.c index be2cbd7024..b62e15cd27 100644 --- a/cpukit/score/src/coretodusectoticks.c +++ b/cpukit/score/src/coretodusectoticks.c @@ -1,4 +1,4 @@ -/* COPYRIGHT (c) 1989-2008. +/* COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -21,5 +21,18 @@ uint32_t TOD_MICROSECONDS_TO_TICKS( uint32_t microseconds ) { - return (microseconds / rtems_configuration_get_microseconds_per_tick()); + uint32_t ticks; + uint32_t microseconds_per_tick; + + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + microseconds_per_tick = rtems_configuration_get_microseconds_per_tick(); + ticks = microseconds / microseconds_per_tick; + if ( (microseconds % microseconds_per_tick) != 0 ) + ticks += 1; + + return ticks; } diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c index ddd82e67a7..10d462976b 100644 --- a/cpukit/score/src/timespectoticks.c +++ b/cpukit/score/src/timespectoticks.c @@ -35,16 +35,22 @@ uint32_t _Timespec_To_ticks( ) { uint32_t ticks; + uint32_t nanoseconds_per_tick; if ( (time->tv_sec == 0) && (time->tv_nsec == 0) ) return 0; - ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + /** + * We should ensure the ticks not be truncated by integer division. We + * need to have it be greater than or equal to the requested time. It + * should not be shorter. + */ + ticks = time->tv_sec * TOD_TICKS_PER_SECOND; + nanoseconds_per_tick = rtems_configuration_get_nanoseconds_per_tick(); + ticks += time->tv_nsec / nanoseconds_per_tick; - ticks += time->tv_nsec / rtems_configuration_get_nanoseconds_per_tick(); + if ( (time->tv_nsec % nanoseconds_per_tick) != 0 ) + ticks += 1; - if (ticks) - return ticks; - - return 1; + return ticks; } -- cgit v1.2.3