From 0a00b2b5f6d115829f05bbac260ba7c9bc47c9e4 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 20 May 2016 13:24:11 +0200 Subject: rtems: Remove location from _Partition_Get() Use _Objects_Get_local() for _Partition_Get() to get rid of the location parameter. Move remote object handling to partition MPCI support. --- cpukit/rtems/src/partdelete.c | 69 +++++++++++++++++------------------- cpukit/rtems/src/partgetbuffer.c | 48 ++++++++++--------------- cpukit/rtems/src/partmp.c | 70 +++++++++++++++++++++++++++---------- cpukit/rtems/src/partreturnbuffer.c | 40 ++++++++------------- 4 files changed, 117 insertions(+), 110 deletions(-) (limited to 'cpukit/rtems/src') diff --git a/cpukit/rtems/src/partdelete.c b/cpukit/rtems/src/partdelete.c index 2df3893b77..972e81eadf 100644 --- a/cpukit/rtems/src/partdelete.c +++ b/cpukit/rtems/src/partdelete.c @@ -26,57 +26,52 @@ rtems_status_code rtems_partition_delete( ) { Partition_Control *the_partition; - Objects_Locations location; ISR_lock_Context lock_context; _Objects_Allocator_lock(); - the_partition = _Partition_Get( id, &location, &lock_context ); - switch ( location ) { + the_partition = _Partition_Get( id, &lock_context ); - case OBJECTS_LOCAL: - _Partition_Acquire_critical( the_partition, &lock_context ); + if ( the_partition == NULL ) { + _Objects_Allocator_unlock(); - if ( the_partition->number_of_used_blocks == 0 ) { - _Objects_Close( &_Partition_Information, &the_partition->Object ); #if defined(RTEMS_MULTIPROCESSING) - if ( _Attributes_Is_global( the_partition->attribute_set ) ) { + if ( _Partition_MP_Is_remote( id ) ) { + return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; + } +#endif - _Objects_MP_Close( - &_Partition_Information, - the_partition->Object.id - ); + return RTEMS_INVALID_ID; + } - _Partition_MP_Send_process_packet( - PARTITION_MP_ANNOUNCE_DELETE, - the_partition->Object.id, - 0, /* Not used */ - 0 /* Not used */ - ); - } -#endif + _Partition_Acquire_critical( the_partition, &lock_context ); - _Partition_Release( the_partition, &lock_context ); - _Partition_Destroy( the_partition ); - _Partition_Free( the_partition ); - _Objects_Allocator_unlock(); - return RTEMS_SUCCESSFUL; - } + if ( the_partition->number_of_used_blocks != 0 ) { + _Partition_Release( the_partition, &lock_context ); + _Objects_Allocator_unlock(); + return RTEMS_RESOURCE_IN_USE; + } - _Partition_Release( the_partition, &lock_context ); - _Objects_Allocator_unlock(); - return RTEMS_RESOURCE_IN_USE; + _Objects_Close( &_Partition_Information, &the_partition->Object ); + _Partition_Release( the_partition, &lock_context ); #if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: - _Objects_Allocator_unlock(); - return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; -#endif + if ( _Attributes_Is_global( the_partition->attribute_set ) ) { + _Objects_MP_Close( + &_Partition_Information, + the_partition->Object.id + ); - case OBJECTS_ERROR: - break; + _Partition_MP_Send_process_packet( + PARTITION_MP_ANNOUNCE_DELETE, + the_partition->Object.id, + 0, /* Not used */ + 0 /* Not used */ + ); } +#endif + _Partition_Destroy( the_partition ); + _Partition_Free( the_partition ); _Objects_Allocator_unlock(); - - return RTEMS_INVALID_ID; + return RTEMS_SUCCESSFUL; } diff --git a/cpukit/rtems/src/partgetbuffer.c b/cpukit/rtems/src/partgetbuffer.c index 39cac5e7b5..42b1b07d25 100644 --- a/cpukit/rtems/src/partgetbuffer.c +++ b/cpukit/rtems/src/partgetbuffer.c @@ -26,45 +26,33 @@ rtems_status_code rtems_partition_get_buffer( ) { Partition_Control *the_partition; - Objects_Locations location; ISR_lock_Context lock_context; void *the_buffer; - if ( !buffer ) + if ( buffer == NULL ) { return RTEMS_INVALID_ADDRESS; + } - the_partition = _Partition_Get( id, &location, &lock_context ); - switch ( location ) { - - case OBJECTS_LOCAL: - _Partition_Acquire_critical( the_partition, &lock_context ); - - the_buffer = _Partition_Allocate_buffer( the_partition ); - if ( the_buffer != NULL ) { - the_partition->number_of_used_blocks += 1; - _Partition_Release( the_partition, &lock_context ); - *buffer = the_buffer; - return RTEMS_SUCCESSFUL; - } - - _Partition_Release( the_partition, &lock_context ); - return RTEMS_UNSATISFIED; + the_partition = _Partition_Get( id, &lock_context ); + if ( the_partition == NULL ) { #if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: - _Thread_Executing->Wait.return_argument = buffer; - return( - _Partition_MP_Send_request_packet( - PARTITION_MP_GET_BUFFER_REQUEST, - id, - 0 /* Not used */ - ) - ); + return _Partition_MP_Get_buffer( id, buffer ); +#else + return RTEMS_INVALID_ID; #endif + } + + _Partition_Acquire_critical( the_partition, &lock_context ); + the_buffer = _Partition_Allocate_buffer( the_partition ); - case OBJECTS_ERROR: - break; + if ( the_buffer == NULL ) { + _Partition_Release( the_partition, &lock_context ); + return RTEMS_UNSATISFIED; } - return RTEMS_INVALID_ID; + the_partition->number_of_used_blocks += 1; + _Partition_Release( the_partition, &lock_context ); + *buffer = the_buffer; + return RTEMS_SUCCESSFUL; } diff --git a/cpukit/rtems/src/partmp.c b/cpukit/rtems/src/partmp.c index 516fe78f73..f094d619eb 100644 --- a/cpukit/rtems/src/partmp.c +++ b/cpukit/rtems/src/partmp.c @@ -33,6 +33,19 @@ static Partition_MP_Packet *_Partition_MP_Get_packet( void ) return (Partition_MP_Packet *) _MPCI_Get_packet(); } +static void _Partition_MP_Initialize_packet( + Partition_MP_Packet *the_packet, + Objects_Id id, + Partition_MP_Remote_operations operation +) +{ + the_packet->Prefix.the_class = MP_PACKET_PARTITION; + the_packet->Prefix.length = sizeof( *the_packet ); + the_packet->Prefix.to_convert = sizeof( *the_packet ); + the_packet->Prefix.id = id; + the_packet->operation = operation; +} + /* * _Partition_MP_Send_process_packet * @@ -54,14 +67,10 @@ void _Partition_MP_Send_process_packet ( case PARTITION_MP_ANNOUNCE_DELETE: case PARTITION_MP_EXTRACT_PROXY: - the_packet = _Partition_MP_Get_packet(); - the_packet->Prefix.the_class = MP_PACKET_PARTITION; - the_packet->Prefix.length = sizeof ( Partition_MP_Packet ); - the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet ); - the_packet->operation = operation; - the_packet->Prefix.id = partition_id; - the_packet->name = name; - the_packet->proxy_id = proxy_id; + the_packet = _Partition_MP_Get_packet(); + _Partition_MP_Initialize_packet( the_packet, partition_id, operation ); + the_packet->name = name; + the_packet->proxy_id = proxy_id; if ( operation == PARTITION_MP_EXTRACT_PROXY ) node = _Objects_Get_node( partition_id ); @@ -84,26 +93,26 @@ void _Partition_MP_Send_process_packet ( * */ -rtems_status_code _Partition_MP_Send_request_packet ( - Partition_MP_Remote_operations operation, +static rtems_status_code _Partition_MP_Send_request_packet ( Objects_Id partition_id, - void *buffer + void *buffer, + Partition_MP_Remote_operations operation ) { Partition_MP_Packet *the_packet; + if ( !_Partition_MP_Is_remote( partition_id ) ) { + return RTEMS_INVALID_ID; + } + switch ( operation ) { case PARTITION_MP_GET_BUFFER_REQUEST: case PARTITION_MP_RETURN_BUFFER_REQUEST: - the_packet = _Partition_MP_Get_packet(); - the_packet->Prefix.the_class = MP_PACKET_PARTITION; - the_packet->Prefix.length = sizeof ( Partition_MP_Packet ); - the_packet->Prefix.to_convert = sizeof ( Partition_MP_Packet ); - the_packet->operation = operation; - the_packet->Prefix.id = partition_id; - the_packet->buffer = buffer; + the_packet = _Partition_MP_Get_packet(); + _Partition_MP_Initialize_packet( the_packet, partition_id, operation ); + the_packet->buffer = buffer; return _MPCI_Send_request_packet( @@ -130,6 +139,31 @@ rtems_status_code _Partition_MP_Send_request_packet ( return RTEMS_SUCCESSFUL; } +rtems_status_code _Partition_MP_Get_buffer( + rtems_id id, + void **buffer +) +{ + _Thread_Get_executing()->Wait.return_argument = buffer; + return _Partition_MP_Send_request_packet( + id, + buffer, + PARTITION_MP_GET_BUFFER_REQUEST + ); +} + +rtems_status_code _Partition_MP_Return_buffer( + rtems_id id, + void *buffer +) +{ + return _Partition_MP_Send_request_packet( + id, + buffer, + PARTITION_MP_RETURN_BUFFER_REQUEST + ); +} + /* * _Partition_MP_Send_response_packet * diff --git a/cpukit/rtems/src/partreturnbuffer.c b/cpukit/rtems/src/partreturnbuffer.c index 641abed572..5d04c63b2a 100644 --- a/cpukit/rtems/src/partreturnbuffer.c +++ b/cpukit/rtems/src/partreturnbuffer.c @@ -22,37 +22,27 @@ rtems_status_code rtems_partition_return_buffer( ) { Partition_Control *the_partition; - Objects_Locations location; ISR_lock_Context lock_context; - the_partition = _Partition_Get( id, &location, &lock_context ); - switch ( location ) { - - case OBJECTS_LOCAL: - _Partition_Acquire_critical( the_partition, &lock_context ); - - if ( _Partition_Is_buffer_valid( buffer, the_partition ) ) { - _Partition_Free_buffer( the_partition, buffer ); - the_partition->number_of_used_blocks -= 1; - _Partition_Release( the_partition, &lock_context ); - return RTEMS_SUCCESSFUL; - } - - _Partition_Release( the_partition, &lock_context ); - return RTEMS_INVALID_ADDRESS; + the_partition = _Partition_Get( id, &lock_context ); + if ( the_partition == NULL ) { #if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: - return _Partition_MP_Send_request_packet( - PARTITION_MP_RETURN_BUFFER_REQUEST, - id, - buffer - ); + return _Partition_MP_Return_buffer( id, buffer ); +#else + return RTEMS_INVALID_ID; #endif + } + + _Partition_Acquire_critical( the_partition, &lock_context ); - case OBJECTS_ERROR: - break; + if ( !_Partition_Is_buffer_valid( buffer, the_partition ) ) { + _Partition_Release( the_partition, &lock_context ); + return RTEMS_INVALID_ADDRESS; } - return RTEMS_INVALID_ID; + _Partition_Free_buffer( the_partition, buffer ); + the_partition->number_of_used_blocks -= 1; + _Partition_Release( the_partition, &lock_context ); + return RTEMS_SUCCESSFUL; } -- cgit v1.2.3