From 9c3bae11b33dce144a9ec460151dad69dfdb6fa9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 21 Apr 2016 07:52:19 +0200 Subject: rtems: Avoid Giant lock for dual ported memory There is no need for an ISR lock since the Dual_ported_memory_Control is immutable after initialization. ISR disable is enough for deletion safety on uni-processor configurations. Update #2555. --- cpukit/rtems/src/dpmemexternal2internal.c | 47 +++++++++++++------------------ 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'cpukit/rtems/src/dpmemexternal2internal.c') diff --git a/cpukit/rtems/src/dpmemexternal2internal.c b/cpukit/rtems/src/dpmemexternal2internal.c index 237d5c4f90..0456010675 100644 --- a/cpukit/rtems/src/dpmemexternal2internal.c +++ b/cpukit/rtems/src/dpmemexternal2internal.c @@ -18,12 +18,8 @@ #include "config.h" #endif -#include -#include -#include -#include #include -#include +#include rtems_status_code rtems_port_external_to_internal( rtems_id id, @@ -31,31 +27,28 @@ rtems_status_code rtems_port_external_to_internal( void **internal ) { - Dual_ported_memory_Control *the_port; - Objects_Locations location; - uint32_t ending; + Dual_ported_memory_Control *the_port; + ISR_lock_Context lock_context; + uint32_t ending; - if ( !internal ) + if ( internal == NULL ) { return RTEMS_INVALID_ADDRESS; + } - the_port = _Dual_ported_memory_Get( id, &location ); - switch ( location ) { - case OBJECTS_LOCAL: - ending = _Addresses_Subtract( external, the_port->external_base ); - if ( ending > the_port->length ) - *internal = external; - else - *internal = _Addresses_Add_offset( the_port->internal_base, - ending ); - _Objects_Put( &the_port->Object ); - return RTEMS_SUCCESSFUL; - -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: /* this error cannot be returned */ -#endif - case OBJECTS_ERROR: - break; + the_port = _Dual_ported_memory_Get( id, &lock_context ); + + if ( the_port == NULL ) { + return RTEMS_INVALID_ID; + } + + ending = _Addresses_Subtract( external, the_port->external_base ); + + if ( ending > the_port->length ) { + *internal = external; + } else { + *internal = _Addresses_Add_offset( the_port->internal_base, ending ); } - return RTEMS_INVALID_ID; + _ISR_lock_ISR_enable( &lock_context ); + return RTEMS_SUCCESSFUL; } -- cgit v1.2.3