[PATCH 10/15] rtems: Remove location from _Partition_Get()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri May 20 13:33:47 UTC 2016


Use _Objects_Get_local() for _Partition_Get() to get rid of the location
parameter.  Move remote object handling to partition MPCI support.
---
 cpukit/rtems/include/rtems/rtems/partimpl.h | 10 ++---
 cpukit/rtems/include/rtems/rtems/partmp.h   | 25 +++++++----
 cpukit/rtems/src/partdelete.c               | 69 +++++++++++++---------------
 cpukit/rtems/src/partgetbuffer.c            | 48 ++++++++------------
 cpukit/rtems/src/partmp.c                   | 70 +++++++++++++++++++++--------
 cpukit/rtems/src/partreturnbuffer.c         | 40 +++++++----------
 6 files changed, 138 insertions(+), 124 deletions(-)

diff --git a/cpukit/rtems/include/rtems/rtems/partimpl.h b/cpukit/rtems/include/rtems/rtems/partimpl.h
index 0ce7622..ea79155 100644
--- a/cpukit/rtems/include/rtems/rtems/partimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/partimpl.h
@@ -181,17 +181,15 @@ RTEMS_INLINE_ROUTINE void _Partition_Free (
   _Objects_Free( &_Partition_Information, &the_partition->Object );
 }
 
-RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get (
+RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get(
   Objects_Id         id,
-  Objects_Locations *location,
   ISR_lock_Context  *lock_context
 )
 {
-  return (Partition_Control *) _Objects_Get_isr_disable(
-    &_Partition_Information,
+  return (Partition_Control *) _Objects_Get_local(
     id,
-    location,
-    lock_context
+    lock_context,
+    &_Partition_Information
   );
 }
 
diff --git a/cpukit/rtems/include/rtems/rtems/partmp.h b/cpukit/rtems/include/rtems/rtems/partmp.h
index e9612e7..b9eaa08 100644
--- a/cpukit/rtems/include/rtems/rtems/partmp.h
+++ b/cpukit/rtems/include/rtems/rtems/partmp.h
@@ -64,6 +64,11 @@ typedef struct {
   Objects_Id                      proxy_id;
 }   Partition_MP_Packet;
 
+RTEMS_INLINE_ROUTINE bool _Partition_MP_Is_remote( Objects_Id id )
+{
+  return _Objects_MP_Is_remote( id, &_Partition_Information );
+}
+
 /**
  *  @brief Partition_MP_Send_process_packet
  *
@@ -80,15 +85,19 @@ void _Partition_MP_Send_process_packet (
 );
 
 /**
- *  @brief Partition_MP_Send_request_packet
- *
- *  This routine performs a remote procedure call so that a
- *  directive operation can be initiated on another node.
+ * @brief Issues a remote rtems_partition_get_buffer() request.
+ */
+rtems_status_code _Partition_MP_Get_buffer(
+  rtems_id   id,
+  void     **buffer
+);
+
+/**
+ * @brief Issues a remote rtems_partition_return_buffer() request.
  */
-rtems_status_code _Partition_MP_Send_request_packet (
-  Partition_MP_Remote_operations  operation,
-  Objects_Id                      partition_id,
-  void                           *buffer
+rtems_status_code _Partition_MP_Return_buffer(
+  rtems_id  id,
+  void     *buffer
 );
 
 /**
diff --git a/cpukit/rtems/src/partdelete.c b/cpukit/rtems/src/partdelete.c
index 2df3893..972e81e 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 39cac5e..42b1b07 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 516fe78..f094d61 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 641abed..5d04c63 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;
 }
-- 
1.8.4.5




More information about the devel mailing list