diff options
Diffstat (limited to 'cpukit/posix/src/timergettime.c')
-rw-r--r-- | cpukit/posix/src/timergettime.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c index f065cc927c..7f0015bf5e 100644 --- a/cpukit/posix/src/timergettime.c +++ b/cpukit/posix/src/timergettime.c @@ -42,31 +42,32 @@ int timer_gettime( { POSIX_Timer_Control *ptimer; Objects_Locations location; - struct timespec current_time; - Watchdog_Interval left; + ISR_lock_Context lock_context; + Per_CPU_Control *cpu; + uint64_t now; + uint32_t remaining; if ( !value ) rtems_set_errno_and_return_minus_one( EINVAL ); - /* Reads the current time */ - _TOD_Get_as_timespec( ¤t_time ); - - ptimer = _POSIX_Timer_Get( timerid, &location ); + ptimer = _POSIX_Timer_Get( timerid, &location, &lock_context ); switch ( location ) { case OBJECTS_LOCAL: - /* Calculates the time left before the timer finishes */ - - left = - (ptimer->Timer.start_time + ptimer->Timer.initial) - /* expire */ - _Watchdog_Ticks_since_boot; /* now */ + cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); + now = cpu->Watchdog.ticks; - _Timespec_From_ticks( left, &value->it_value ); + if ( now < ptimer->Timer.expire ) { + remaining = (uint32_t) ( ptimer->Timer.expire - now ); + } else { + remaining = 0; + } - value->it_interval = ptimer->timer_data.it_interval; + _Timespec_From_ticks( remaining, &value->it_value ); + value->it_interval = ptimer->timer_data.it_interval; - _Objects_Put( &ptimer->Object ); + _POSIX_Timer_Release( cpu, &lock_context ); return 0; #if defined(RTEMS_MULTIPROCESSING) |