From 77e6eba7146ba2e2074b719eec01cc7c40bbe98b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 7 Mar 2016 16:01:57 +0100 Subject: score: Add and use _Objects_Get_local() This simplifies the handling with local-only objects. Update #2555. --- cpukit/posix/include/rtems/posix/timerimpl.h | 4 +- cpukit/posix/src/timerdelete.c | 36 +++++-------- cpukit/posix/src/timergetoverrun.c | 26 ++++------ cpukit/posix/src/timergettime.c | 37 +++++-------- cpukit/posix/src/timersettime.c | 78 +++++++++++++--------------- 5 files changed, 73 insertions(+), 108 deletions(-) (limited to 'cpukit/posix') diff --git a/cpukit/posix/include/rtems/posix/timerimpl.h b/cpukit/posix/include/rtems/posix/timerimpl.h index 2eefd7063c..bf25629529 100644 --- a/cpukit/posix/include/rtems/posix/timerimpl.h +++ b/cpukit/posix/include/rtems/posix/timerimpl.h @@ -94,14 +94,12 @@ void _POSIX_Timer_TSR( Watchdog_Control *the_watchdog ); */ RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Get ( timer_t id, - Objects_Locations *location, ISR_lock_Context *lock_context ) { - return (POSIX_Timer_Control *) _Objects_Get_isr_disable( + return (POSIX_Timer_Control *) _Objects_Get_local( &_POSIX_Timer_Information, (Objects_Id) id, - location, lock_context ); } diff --git a/cpukit/posix/src/timerdelete.c b/cpukit/posix/src/timerdelete.c index c39de8e168..5301a708c9 100644 --- a/cpukit/posix/src/timerdelete.c +++ b/cpukit/posix/src/timerdelete.c @@ -44,33 +44,25 @@ int timer_delete( * because rtems_timer_delete stops the timer before deleting it. */ POSIX_Timer_Control *ptimer; - Objects_Locations location; ISR_lock_Context lock_context; - Per_CPU_Control *cpu; _Objects_Allocator_lock(); - ptimer = _POSIX_Timer_Get( timerid, &location, &lock_context ); - switch ( location ) { - case OBJECTS_LOCAL: - _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object ); - cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); - ptimer->state = POSIX_TIMER_STATE_FREE; - _Watchdog_Remove( - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ], - &ptimer->Timer - ); - _POSIX_Timer_Release( cpu, &lock_context ); - _POSIX_Timer_Free( ptimer ); - _Objects_Allocator_unlock(); + ptimer = _POSIX_Timer_Get( timerid, &lock_context ); + if ( ptimer != NULL ) { + Per_CPU_Control *cpu; - return 0; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object ); + cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); + ptimer->state = POSIX_TIMER_STATE_FREE; + _Watchdog_Remove( + &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ], + &ptimer->Timer + ); + _POSIX_Timer_Release( cpu, &lock_context ); + _POSIX_Timer_Free( ptimer ); + _Objects_Allocator_unlock(); + return 0; } _Objects_Allocator_unlock(); diff --git a/cpukit/posix/src/timergetoverrun.c b/cpukit/posix/src/timergetoverrun.c index 0a28fa7b5f..0a7b9fafa6 100644 --- a/cpukit/posix/src/timergetoverrun.c +++ b/cpukit/posix/src/timergetoverrun.c @@ -30,27 +30,19 @@ int timer_getoverrun( timer_t timerid ) { - int overrun; POSIX_Timer_Control *ptimer; - Objects_Locations location; ISR_lock_Context lock_context; - Per_CPU_Control *cpu; - ptimer = _POSIX_Timer_Get( timerid, &location, &lock_context ); - switch ( location ) { + ptimer = _POSIX_Timer_Get( timerid, &lock_context ); + if ( ptimer != NULL ) { + Per_CPU_Control *cpu; + int overrun; - case OBJECTS_LOCAL: - cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); - overrun = ptimer->overrun; - ptimer->overrun = 0; - _POSIX_Timer_Release( cpu, &lock_context ); - return overrun; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); + overrun = ptimer->overrun; + ptimer->overrun = 0; + _POSIX_Timer_Release( cpu, &lock_context ); + return overrun; } rtems_set_errno_and_return_minus_one( EINVAL ); diff --git a/cpukit/posix/src/timergettime.c b/cpukit/posix/src/timergettime.c index 7f0015bf5e..66708e947b 100644 --- a/cpukit/posix/src/timergettime.c +++ b/cpukit/posix/src/timergettime.c @@ -41,40 +41,31 @@ int timer_gettime( ) { POSIX_Timer_Control *ptimer; - Objects_Locations location; 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 ); - ptimer = _POSIX_Timer_Get( timerid, &location, &lock_context ); - switch ( location ) { + ptimer = _POSIX_Timer_Get( timerid, &lock_context ); + if ( ptimer != NULL ) { + Per_CPU_Control *cpu; - case OBJECTS_LOCAL: + cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); + now = cpu->Watchdog.ticks; - cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); - now = cpu->Watchdog.ticks; + if ( now < ptimer->Timer.expire ) { + remaining = (uint32_t) ( ptimer->Timer.expire - now ); + } else { + remaining = 0; + } - if ( now < ptimer->Timer.expire ) { - remaining = (uint32_t) ( ptimer->Timer.expire - now ); - } else { - remaining = 0; - } + _Timespec_From_ticks( remaining, &value->it_value ); + value->it_interval = ptimer->timer_data.it_interval; - _Timespec_From_ticks( remaining, &value->it_value ); - value->it_interval = ptimer->timer_data.it_interval; - - _POSIX_Timer_Release( cpu, &lock_context ); - return 0; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + _POSIX_Timer_Release( cpu, &lock_context ); + return 0; } rtems_set_errno_and_return_minus_one( EINVAL ); diff --git a/cpukit/posix/src/timersettime.c b/cpukit/posix/src/timersettime.c index ac5c258eda..51678ca5cb 100644 --- a/cpukit/posix/src/timersettime.c +++ b/cpukit/posix/src/timersettime.c @@ -107,9 +107,7 @@ int timer_settime( ) { POSIX_Timer_Control *ptimer; - Objects_Locations location; ISR_lock_Context lock_context; - Per_CPU_Control *cpu; uint32_t initial_period; struct itimerspec normalize; @@ -148,53 +146,47 @@ int timer_settime( * or start it again */ - ptimer = _POSIX_Timer_Get( timerid, &location, &lock_context ); - switch ( location ) { - - case OBJECTS_LOCAL: - cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); - - /* Stop the timer */ - _Watchdog_Remove( - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ], - &ptimer->Timer - ); - - /* First, it verifies if the timer must be stopped */ - if ( normalize.it_value.tv_sec == 0 && normalize.it_value.tv_nsec == 0 ) { - /* The old data of the timer are returned */ - if ( ovalue ) - *ovalue = ptimer->timer_data; - /* The new data are set */ - ptimer->timer_data = normalize; - /* Indicates that the timer is created and stopped */ - ptimer->state = POSIX_TIMER_STATE_CREATE_STOP; - /* Returns with success */ - _POSIX_Timer_Release( cpu, &lock_context ); - return 0; - } - - /* Convert from seconds and nanoseconds to ticks */ - ptimer->ticks = _Timespec_To_ticks( &value->it_interval ); - initial_period = _Timespec_To_ticks( &normalize.it_value ); - - _POSIX_Timer_Insert( ptimer, cpu, initial_period ); - - /* - * The timer has been started and is running. So we return the - * old ones in "ovalue" - */ + ptimer = _POSIX_Timer_Get( timerid, &lock_context ); + if ( ptimer != NULL ) { + Per_CPU_Control *cpu; + + cpu = _POSIX_Timer_Acquire_critical( ptimer, &lock_context ); + + /* Stop the timer */ + _Watchdog_Remove( + &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ], + &ptimer->Timer + ); + + /* First, it verifies if the timer must be stopped */ + if ( normalize.it_value.tv_sec == 0 && normalize.it_value.tv_nsec == 0 ) { + /* The old data of the timer are returned */ if ( ovalue ) *ovalue = ptimer->timer_data; + /* The new data are set */ ptimer->timer_data = normalize; + /* Indicates that the timer is created and stopped */ + ptimer->state = POSIX_TIMER_STATE_CREATE_STOP; + /* Returns with success */ _POSIX_Timer_Release( cpu, &lock_context ); return 0; + } -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: -#endif - case OBJECTS_ERROR: - break; + /* Convert from seconds and nanoseconds to ticks */ + ptimer->ticks = _Timespec_To_ticks( &value->it_interval ); + initial_period = _Timespec_To_ticks( &normalize.it_value ); + + _POSIX_Timer_Insert( ptimer, cpu, initial_period ); + + /* + * The timer has been started and is running. So we return the + * old ones in "ovalue" + */ + if ( ovalue ) + *ovalue = ptimer->timer_data; + ptimer->timer_data = normalize; + _POSIX_Timer_Release( cpu, &lock_context ); + return 0; } rtems_set_errno_and_return_minus_one( EINVAL ); -- cgit v1.2.3