[PATCH 12/15] rtems: _Semaphore_Get_interrupt_disable()

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


Use _Objects_Get_local() for _Semaphore_Get_interrupt_disable() to get
rid of the location parameter.  Move remote object handling to semaphore
MPCI support.
---
 cpukit/rtems/include/rtems/rtems/semimpl.h |  21 +--
 cpukit/rtems/include/rtems/rtems/semmp.h   |  24 ++--
 cpukit/rtems/src/semdelete.c               | 198 +++++++++++++----------------
 cpukit/rtems/src/semflush.c                | 105 +++++++--------
 cpukit/rtems/src/semmp.c                   |  30 ++++-
 cpukit/rtems/src/semobtain.c               | 126 ++++++++----------
 cpukit/rtems/src/semrelease.c              | 111 ++++++----------
 cpukit/rtems/src/semsetpriority.c          |  28 ++--
 testsuites/sptests/spintrcritical22/init.c |   3 +-
 testsuites/tmtests/tm26/task1.c            |   3 -
 10 files changed, 287 insertions(+), 362 deletions(-)

diff --git a/cpukit/rtems/include/rtems/rtems/semimpl.h b/cpukit/rtems/include/rtems/rtems/semimpl.h
index b67b415..7c26c24 100644
--- a/cpukit/rtems/include/rtems/rtems/semimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/semimpl.h
@@ -134,28 +134,15 @@ RTEMS_INLINE_ROUTINE void _Semaphore_Free (
   _Objects_Free( &_Semaphore_Information, &the_semaphore->Object );
 }
 
-/**
- *  @brief Maps semaphore IDs to semaphore control blocks.
- *
- *  This function maps semaphore IDs to semaphore control blocks.
- *  If ID corresponds to a local semaphore, then it returns
- *  the_semaphore control pointer which maps to ID and location
- *  is set to OBJECTS_LOCAL.  if the semaphore ID is global and
- *  resides on a remote node, then location is set to OBJECTS_REMOTE,
- *  and the_semaphore is undefined.  Otherwise, location is set
- *  to OBJECTS_ERROR and the_semaphore is undefined.
- */
-RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get_interrupt_disable (
+RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Get_interrupt_disable(
   Objects_Id         id,
-  Objects_Locations *location,
   ISR_lock_Context  *lock_context
 )
 {
-  return (Semaphore_Control *) _Objects_Get_isr_disable(
-    &_Semaphore_Information,
+  return (Semaphore_Control *) _Objects_Get_local(
     id,
-    location,
-    lock_context
+    lock_context,
+    &_Semaphore_Information
   );
 }
 
diff --git a/cpukit/rtems/include/rtems/rtems/semmp.h b/cpukit/rtems/include/rtems/rtems/semmp.h
index d186aa0..9d7669f 100644
--- a/cpukit/rtems/include/rtems/rtems/semmp.h
+++ b/cpukit/rtems/include/rtems/rtems/semmp.h
@@ -65,6 +65,11 @@ typedef struct {
   Objects_Id                      proxy_id;
 }   Semaphore_MP_Packet;
 
+RTEMS_INLINE_ROUTINE bool _Semaphore_MP_Is_remote( Objects_Id id )
+{
+  return _Objects_MP_Is_remote( id, &_Semaphore_Information );
+}
+
 /**
  *  @brief Semaphore MP Send Process Packet
  *
@@ -79,19 +84,20 @@ void _Semaphore_MP_Send_process_packet (
 );
 
 /**
- *  @brief Semaphore 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_semaphore_obtain() request.
  */
-rtems_status_code _Semaphore_MP_Send_request_packet (
-  Semaphore_MP_Remote_operations operation,
-  Objects_Id                     semaphore_id,
-  rtems_option                   option_set,
-  rtems_interval                 timeout
+rtems_status_code _Semaphore_MP_Obtain(
+  rtems_id        id,
+  rtems_option    option_set,
+  rtems_interval  timeout
 );
 
 /**
+ * @brief Issues a remote rtems_semaphore_release() request.
+ */
+rtems_status_code _Semaphore_MP_Release( rtems_id id );
+
+/**
  *  @brief Semaphore MP Process Packet
  *
  *  This routine performs the actions specific to this package for
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index eebe88a..38d4a0e 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -18,135 +18,117 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/support.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/score/isr.h>
-#include <rtems/rtems/options.h>
 #include <rtems/rtems/semimpl.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/coresemimpl.h>
-#include <rtems/score/thread.h>
-
-#include <rtems/score/interr.h>
+#include <rtems/rtems/attrimpl.h>
 
 rtems_status_code rtems_semaphore_delete(
   rtems_id   id
 )
 {
-  Semaphore_Control          *the_semaphore;
-  Objects_Locations           location;
-  ISR_lock_Context            lock_context;
-  rtems_attribute             attribute_set;
+  Semaphore_Control *the_semaphore;
+  ISR_lock_Context   lock_context;
+  rtems_attribute    attribute_set;
 
   _Objects_Allocator_lock();
+  the_semaphore = _Semaphore_Get_interrupt_disable( id, &lock_context );
 
-  the_semaphore = _Semaphore_Get_interrupt_disable(
-    id,
-    &location,
-    &lock_context
-  );
-  switch ( location ) {
+  if ( the_semaphore == NULL ) {
+    _Objects_Allocator_unlock();
 
-    case OBJECTS_LOCAL:
-      attribute_set = the_semaphore->attribute_set;
-#if defined(RTEMS_SMP)
-      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
-        MRSP_Status mrsp_status;
-
-        _MRSP_Acquire_critical(
-          &the_semaphore->Core_control.mrsp,
-          &lock_context
-        );
-        mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
-        if ( mrsp_status != MRSP_SUCCESSFUL ) {
-          _MRSP_Release(
-            &the_semaphore->Core_control.mrsp,
-            &lock_context
-          );
-          _Objects_Allocator_unlock();
-          return _Semaphore_Translate_MRSP_status_code( mrsp_status );
-        }
-      } else
+#if defined(RTEMS_MULTIPROCESSING)
+    if ( _Semaphore_MP_Is_remote( id ) ) {
+      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+    }
 #endif
-      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
-        _CORE_mutex_Acquire_critical(
-          &the_semaphore->Core_control.mutex,
-          &lock_context
-        );
-
-        if (
-          _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
-            && !_Attributes_Is_simple_binary_semaphore( attribute_set )
-        ) {
-          _CORE_mutex_Release(
-            &the_semaphore->Core_control.mutex,
-            &lock_context
-          );
-          _Objects_Allocator_unlock();
-          return RTEMS_RESOURCE_IN_USE;
-        }
-      } else {
-        _CORE_semaphore_Acquire_critical(
-          &the_semaphore->Core_control.semaphore,
-          &lock_context
-        );
-      }
-
-      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
+
+    return RTEMS_INVALID_ID;
+  }
+
+  attribute_set = the_semaphore->attribute_set;
 
 #if defined(RTEMS_SMP)
-      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
-        _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &lock_context );
-      } else
+  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+    MRSP_Status mrsp_status;
+
+    _MRSP_Acquire_critical(
+      &the_semaphore->Core_control.mrsp,
+      &lock_context
+    );
+    mrsp_status = _MRSP_Can_destroy( &the_semaphore->Core_control.mrsp );
+    if ( mrsp_status != MRSP_SUCCESSFUL ) {
+      _MRSP_Release(
+        &the_semaphore->Core_control.mrsp,
+        &lock_context
+      );
+      _Objects_Allocator_unlock();
+      return _Semaphore_Translate_MRSP_status_code( mrsp_status );
+    }
+  } else
 #endif
-      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
-        _CORE_mutex_Flush(
-          &the_semaphore->Core_control.mutex,
-          _CORE_mutex_Was_deleted,
-          _Semaphore_MP_Send_object_was_deleted,
-          id,
-          &lock_context
-        );
-        _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
-      } else {
-        _CORE_semaphore_Destroy(
-          &the_semaphore->Core_control.semaphore,
-          _Semaphore_MP_Send_object_was_deleted,
-          id,
-          &lock_context
-        );
-      }
-
-#if defined(RTEMS_MULTIPROCESSING)
-      if ( _Attributes_Is_global( attribute_set ) ) {
+  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
+    _CORE_mutex_Acquire_critical(
+      &the_semaphore->Core_control.mutex,
+      &lock_context
+    );
+
+    if (
+      _CORE_mutex_Is_locked( &the_semaphore->Core_control.mutex )
+        && !_Attributes_Is_simple_binary_semaphore( attribute_set )
+    ) {
+      _CORE_mutex_Release(
+        &the_semaphore->Core_control.mutex,
+        &lock_context
+      );
+      _Objects_Allocator_unlock();
+      return RTEMS_RESOURCE_IN_USE;
+    }
+  } else {
+    _CORE_semaphore_Acquire_critical(
+      &the_semaphore->Core_control.semaphore,
+      &lock_context
+    );
+  }
 
-        _Objects_MP_Close( &_Semaphore_Information, id );
+  _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
 
-        _Semaphore_MP_Send_process_packet(
-          SEMAPHORE_MP_ANNOUNCE_DELETE,
-          id,
-          0,                         /* Not used */
-          0                          /* Not used */
-        );
-      }
+#if defined(RTEMS_SMP)
+  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+    _MRSP_Destroy( &the_semaphore->Core_control.mrsp, &lock_context );
+  } else
 #endif
-
-      _Semaphore_Free( the_semaphore );
-      _Objects_Allocator_unlock();
-      return RTEMS_SUCCESSFUL;
+  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
+    _CORE_mutex_Flush(
+      &the_semaphore->Core_control.mutex,
+      _CORE_mutex_Was_deleted,
+      _Semaphore_MP_Send_object_was_deleted,
+      id,
+      &lock_context
+    );
+    _CORE_mutex_Destroy( &the_semaphore->Core_control.mutex );
+  } else {
+    _CORE_semaphore_Destroy(
+      &the_semaphore->Core_control.semaphore,
+      _Semaphore_MP_Send_object_was_deleted,
+      id,
+      &lock_context
+    );
+  }
 
 #if defined(RTEMS_MULTIPROCESSING)
-    case OBJECTS_REMOTE:
-      _Objects_Allocator_unlock();
-      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
-#endif
+  if ( _Attributes_Is_global( attribute_set ) ) {
 
-    case OBJECTS_ERROR:
-      break;
+    _Objects_MP_Close( &_Semaphore_Information, id );
+
+    _Semaphore_MP_Send_process_packet(
+      SEMAPHORE_MP_ANNOUNCE_DELETE,
+      id,
+      0,                         /* Not used */
+      0                          /* Not used */
+    );
   }
+#endif
 
+  _Semaphore_Free( the_semaphore );
   _Objects_Allocator_unlock();
-  return RTEMS_INVALID_ID;
+  return RTEMS_SUCCESSFUL;
 }
diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
index 13dcf22..3b1cdb5 100644
--- a/cpukit/rtems/src/semflush.c
+++ b/cpukit/rtems/src/semflush.c
@@ -18,77 +18,58 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/support.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/score/isr.h>
-#include <rtems/rtems/options.h>
 #include <rtems/rtems/semimpl.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/coresemimpl.h>
-#include <rtems/score/thread.h>
-
-#include <rtems/score/interr.h>
+#include <rtems/rtems/attrimpl.h>
 
-rtems_status_code rtems_semaphore_flush(
-  rtems_id        id
-)
+rtems_status_code rtems_semaphore_flush( rtems_id id )
 {
-  Semaphore_Control          *the_semaphore;
-  Objects_Locations           location;
-  ISR_lock_Context            lock_context;
-  rtems_attribute             attribute_set;
+  Semaphore_Control *the_semaphore;
+  ISR_lock_Context   lock_context;
+  rtems_attribute    attribute_set;
 
-  the_semaphore = _Semaphore_Get_interrupt_disable(
-    id,
-    &location,
-    &lock_context
-  );
-  switch ( location ) {
-
-    case OBJECTS_LOCAL:
-      attribute_set = the_semaphore->attribute_set;
-#if defined(RTEMS_SMP)
-      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
-        _ISR_lock_ISR_enable( &lock_context );
-        return RTEMS_NOT_DEFINED;
-      } else
-#endif
-      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
-        _CORE_mutex_Acquire_critical(
-          &the_semaphore->Core_control.mutex,
-          &lock_context
-        );
-        _CORE_mutex_Flush(
-          &the_semaphore->Core_control.mutex,
-          _CORE_mutex_Unsatisfied_nowait,
-          _Semaphore_MP_Send_object_was_deleted,
-          id,
-          &lock_context
-        );
-      } else {
-        _CORE_semaphore_Acquire_critical(
-          &the_semaphore->Core_control.semaphore,
-          &lock_context
-        );
-        _CORE_semaphore_Flush(
-          &the_semaphore->Core_control.semaphore,
-          _Semaphore_MP_Send_object_was_deleted,
-          id,
-          &lock_context
-        );
-      }
-      return RTEMS_SUCCESSFUL;
+  the_semaphore = _Semaphore_Get_interrupt_disable( id, &lock_context );
 
+  if ( the_semaphore == NULL ) {
 #if defined(RTEMS_MULTIPROCESSING)
-    case OBJECTS_REMOTE:
+    if ( _Semaphore_MP_Is_remote( id ) ) {
       return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+    }
 #endif
 
-    case OBJECTS_ERROR:
-      break;
+    return RTEMS_INVALID_ID;
   }
 
-  return RTEMS_INVALID_ID;
+  attribute_set = the_semaphore->attribute_set;
+
+#if defined(RTEMS_SMP)
+  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+    _ISR_lock_ISR_enable( &lock_context );
+    return RTEMS_NOT_DEFINED;
+  } else
+#endif
+  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
+    _CORE_mutex_Acquire_critical(
+      &the_semaphore->Core_control.mutex,
+      &lock_context
+    );
+    _CORE_mutex_Flush(
+      &the_semaphore->Core_control.mutex,
+      _CORE_mutex_Unsatisfied_nowait,
+      _Semaphore_MP_Send_object_was_deleted,
+      id,
+      &lock_context
+    );
+  } else {
+    _CORE_semaphore_Acquire_critical(
+      &the_semaphore->Core_control.semaphore,
+      &lock_context
+    );
+    _CORE_semaphore_Flush(
+      &the_semaphore->Core_control.semaphore,
+      _Semaphore_MP_Send_object_was_deleted,
+      id,
+      &lock_context
+    );
+  }
+  return RTEMS_SUCCESSFUL;
 }
diff --git a/cpukit/rtems/src/semmp.c b/cpukit/rtems/src/semmp.c
index 7b9c39b..7f7506c 100644
--- a/cpukit/rtems/src/semmp.c
+++ b/cpukit/rtems/src/semmp.c
@@ -72,11 +72,11 @@ void _Semaphore_MP_Send_process_packet (
   }
 }
 
-rtems_status_code _Semaphore_MP_Send_request_packet (
-  Semaphore_MP_Remote_operations operation,
+static rtems_status_code _Semaphore_MP_Send_request_packet(
   Objects_Id                     semaphore_id,
   rtems_option                   option_set,
-  rtems_interval                 timeout
+  rtems_interval                 timeout,
+  Semaphore_MP_Remote_operations operation
 )
 {
   Semaphore_MP_Packet *the_packet;
@@ -120,6 +120,30 @@ rtems_status_code _Semaphore_MP_Send_request_packet (
   return RTEMS_SUCCESSFUL;
 }
 
+rtems_status_code _Semaphore_MP_Obtain(
+  rtems_id        id,
+  rtems_option    option_set,
+  rtems_interval  timeout
+)
+{
+  return _Semaphore_MP_Send_request_packet(
+    id,
+    option_set,
+    timeout,
+    SEMAPHORE_MP_OBTAIN_REQUEST
+  );
+}
+
+rtems_status_code _Semaphore_MP_Release( rtems_id id )
+{
+  return _Semaphore_MP_Send_request_packet(
+    id,
+    0,
+    MPCI_DEFAULT_TIMEOUT,
+    SEMAPHORE_MP_RELEASE_REQUEST
+  );
+}
+
 static void _Semaphore_MP_Send_response_packet (
   Semaphore_MP_Remote_operations  operation,
   Objects_Id                      semaphore_id,
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index e3d6f3c..b3dcd3c 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -18,18 +18,10 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/support.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/score/isr.h>
-#include <rtems/rtems/optionsimpl.h>
 #include <rtems/rtems/semimpl.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/coresemimpl.h>
 #include <rtems/score/threadimpl.h>
-
-#include <rtems/score/interr.h>
+#include <rtems/rtems/attrimpl.h>
+#include <rtems/rtems/optionsimpl.h>
 
 THREAD_WAIT_QUEUE_OBJECT_ASSERT(
   Semaphore_Control,
@@ -47,76 +39,62 @@ rtems_status_code rtems_semaphore_obtain(
   rtems_interval  timeout
 )
 {
-  Semaphore_Control              *the_semaphore;
-  Objects_Locations               location;
-  ISR_lock_Context                lock_context;
-  Thread_Control                 *executing;
-  rtems_attribute                 attribute_set;
-  bool                            wait;
-
-  the_semaphore = _Semaphore_Get_interrupt_disable(
-    id,
-    &location,
-    &lock_context
-  );
-  switch ( location ) {
-
-    case OBJECTS_LOCAL:
-      executing = _Thread_Executing;
-      attribute_set = the_semaphore->attribute_set;
-      wait = !_Options_Is_no_wait( option_set );
-#if defined(RTEMS_SMP)
-      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
-        MRSP_Status mrsp_status;
-
-        mrsp_status = _MRSP_Seize(
-          &the_semaphore->Core_control.mrsp,
-          executing,
-          wait,
-          timeout,
-          &lock_context
-        );
-        return _Semaphore_Translate_MRSP_status_code( mrsp_status );
-      } else
-#endif
-      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
-        _CORE_mutex_Seize(
-          &the_semaphore->Core_control.mutex,
-          executing,
-          wait,
-          timeout,
-          &lock_context
-        );
-        return _Semaphore_Translate_core_mutex_return_code(
-                  executing->Wait.return_code );
-      }
+  Semaphore_Control *the_semaphore;
+  ISR_lock_Context   lock_context;
+  Thread_Control    *executing;
+  rtems_attribute    attribute_set;
+  bool               wait;
 
-      /* must be a counting semaphore */
-      _CORE_semaphore_Seize(
-        &the_semaphore->Core_control.semaphore,
-        executing,
-        id,
-        wait,
-        timeout,
-        &lock_context
-      );
-      return _Semaphore_Translate_core_semaphore_return_code(
-                  executing->Wait.return_code );
+  the_semaphore = _Semaphore_Get_interrupt_disable( id, &lock_context );
 
+  if ( the_semaphore == NULL ) {
 #if defined(RTEMS_MULTIPROCESSING)
-    case OBJECTS_REMOTE:
-      return _Semaphore_MP_Send_request_packet(
-          SEMAPHORE_MP_OBTAIN_REQUEST,
-          id,
-          option_set,
-          timeout
-      );
+    _Semaphore_MP_Obtain( id, option_set, timeout );
+#else
+    return RTEMS_INVALID_ID;
 #endif
+  }
 
-    case OBJECTS_ERROR:
-      break;
+  executing = _Thread_Executing;
+  attribute_set = the_semaphore->attribute_set;
+  wait = !_Options_Is_no_wait( option_set );
+#if defined(RTEMS_SMP)
+  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+    MRSP_Status mrsp_status;
 
+    mrsp_status = _MRSP_Seize(
+      &the_semaphore->Core_control.mrsp,
+      executing,
+      wait,
+      timeout,
+      &lock_context
+    );
+    return _Semaphore_Translate_MRSP_status_code( mrsp_status );
+  } else
+#endif
+  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
+    _CORE_mutex_Seize(
+      &the_semaphore->Core_control.mutex,
+      executing,
+      wait,
+      timeout,
+      &lock_context
+    );
+    return _Semaphore_Translate_core_mutex_return_code(
+      executing->Wait.return_code
+    );
   }
 
-  return RTEMS_INVALID_ID;
+  /* must be a counting semaphore */
+  _CORE_semaphore_Seize(
+    &the_semaphore->Core_control.semaphore,
+    executing,
+    id,
+    wait,
+    timeout,
+    &lock_context
+  );
+  return _Semaphore_Translate_core_semaphore_return_code(
+    executing->Wait.return_code
+  );
 }
diff --git a/cpukit/rtems/src/semrelease.c b/cpukit/rtems/src/semrelease.c
index 762328c..2ebf5c0 100644
--- a/cpukit/rtems/src/semrelease.c
+++ b/cpukit/rtems/src/semrelease.c
@@ -21,82 +21,55 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/support.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/score/isr.h>
-#include <rtems/rtems/options.h>
 #include <rtems/rtems/semimpl.h>
-#include <rtems/score/coremuteximpl.h>
-#include <rtems/score/coresemimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/interr.h>
+#include <rtems/rtems/attrimpl.h>
 
-rtems_status_code rtems_semaphore_release(
-  rtems_id   id
-)
+rtems_status_code rtems_semaphore_release( rtems_id id )
 {
-  Semaphore_Control          *the_semaphore;
-  Objects_Locations           location;
-  CORE_mutex_Status           mutex_status;
-  CORE_semaphore_Status       semaphore_status;
-  rtems_attribute             attribute_set;
-  ISR_lock_Context            lock_context;
-
-  the_semaphore = _Semaphore_Get_interrupt_disable(
-    id,
-    &location,
-    &lock_context
-  );
-  switch ( location ) {
+  Semaphore_Control     *the_semaphore;
+  CORE_mutex_Status      mutex_status;
+  CORE_semaphore_Status  semaphore_status;
+  rtems_attribute        attribute_set;
+  ISR_lock_Context       lock_context;
 
-    case OBJECTS_LOCAL:
-      attribute_set = the_semaphore->attribute_set;
-#if defined(RTEMS_SMP)
-      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
-        MRSP_Status mrsp_status;
-
-        mrsp_status = _MRSP_Surrender(
-          &the_semaphore->Core_control.mrsp,
-          _Thread_Executing,
-          &lock_context
-        );
-        return _Semaphore_Translate_MRSP_status_code( mrsp_status );
-      } else
-#endif
-      if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
-        mutex_status = _CORE_mutex_Surrender(
-          &the_semaphore->Core_control.mutex,
-          _Semaphore_Core_mutex_mp_support,
-          id,
-          &lock_context
-        );
-        return _Semaphore_Translate_core_mutex_return_code( mutex_status );
-      } else {
-        semaphore_status = _CORE_semaphore_Surrender(
-          &the_semaphore->Core_control.semaphore,
-          _Semaphore_Core_mutex_mp_support,
-          id,
-          &lock_context
-        );
-        return
-          _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
-      }
+  the_semaphore = _Semaphore_Get_interrupt_disable( id, &lock_context );
 
+  if ( the_semaphore == NULL ) {
 #if defined(RTEMS_MULTIPROCESSING)
-    case OBJECTS_REMOTE:
-      return _Semaphore_MP_Send_request_packet(
-        SEMAPHORE_MP_RELEASE_REQUEST,
-        id,
-        0,                               /* Not used */
-        MPCI_DEFAULT_TIMEOUT
-      );
+    _Semaphore_MP_Release( id );
+#else
+    return RTEMS_INVALID_ID;
 #endif
-
-    case OBJECTS_ERROR:
-      break;
   }
 
-  return RTEMS_INVALID_ID;
+  attribute_set = the_semaphore->attribute_set;
+#if defined(RTEMS_SMP)
+  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
+    MRSP_Status mrsp_status;
+
+    mrsp_status = _MRSP_Surrender(
+      &the_semaphore->Core_control.mrsp,
+      _Thread_Executing,
+      &lock_context
+    );
+    return _Semaphore_Translate_MRSP_status_code( mrsp_status );
+  } else
+#endif
+  if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
+    mutex_status = _CORE_mutex_Surrender(
+      &the_semaphore->Core_control.mutex,
+      _Semaphore_Core_mutex_mp_support,
+      id,
+      &lock_context
+    );
+    return _Semaphore_Translate_core_mutex_return_code( mutex_status );
+  } else {
+    semaphore_status = _CORE_semaphore_Surrender(
+      &the_semaphore->Core_control.semaphore,
+      _Semaphore_Core_mutex_mp_support,
+      id,
+      &lock_context
+    );
+    return _Semaphore_Translate_core_semaphore_return_code( semaphore_status );
+  }
 }
diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c
index 1073a56..3c6ad27 100644
--- a/cpukit/rtems/src/semsetpriority.c
+++ b/cpukit/rtems/src/semsetpriority.c
@@ -88,7 +88,6 @@ rtems_status_code rtems_semaphore_set_priority(
 )
 {
   Semaphore_Control *the_semaphore;
-  Objects_Locations  location;
   ISR_lock_Context   lock_context;
 
   if ( new_priority != RTEMS_CURRENT_PRIORITY &&
@@ -106,25 +105,24 @@ rtems_status_code rtems_semaphore_set_priority(
 
   the_semaphore = _Semaphore_Get_interrupt_disable(
     semaphore_id,
-    &location,
     &lock_context
   );
-  switch ( location ) {
-    case OBJECTS_LOCAL:
-      return _Semaphore_Set_priority(
-        the_semaphore,
-        scheduler_id,
-        new_priority,
-        old_priority,
-        &lock_context
-      );
+
+  if ( the_semaphore == NULL ) {
 #if defined(RTEMS_MULTIPROCESSING)
-    case OBJECTS_REMOTE:
+    if ( _Semaphore_MP_Is_remote( semaphore_id ) ) {
       return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
+    }
 #endif
-    case OBJECTS_ERROR:
-      break;
+
+    return RTEMS_INVALID_ID;
   }
 
-  return RTEMS_INVALID_ID;
+  return _Semaphore_Set_priority(
+    the_semaphore,
+    scheduler_id,
+    new_priority,
+    old_priority,
+    &lock_context
+  );
 }
diff --git a/testsuites/sptests/spintrcritical22/init.c b/testsuites/sptests/spintrcritical22/init.c
index aada98d..cbb23ab 100644
--- a/testsuites/sptests/spintrcritical22/init.c
+++ b/testsuites/sptests/spintrcritical22/init.c
@@ -33,11 +33,10 @@ static test_context ctx_instance;
 
 static Semaphore_Control *get_semaphore_control(rtems_id id)
 {
-  Objects_Locations location;
   ISR_lock_Context lock_context;
   Semaphore_Control *sem;
 
-  sem = _Semaphore_Get_interrupt_disable(id, &location, &lock_context);
+  sem = _Semaphore_Get_interrupt_disable(id, &lock_context);
   rtems_test_assert(sem != NULL);
   _ISR_lock_ISR_enable(&lock_context);
 
diff --git a/testsuites/tmtests/tm26/task1.c b/testsuites/tmtests/tm26/task1.c
index 69fdc48..52348df 100644
--- a/testsuites/tmtests/tm26/task1.c
+++ b/testsuites/tmtests/tm26/task1.c
@@ -31,8 +31,6 @@ const char rtems_test_name[] = "TIME TEST 26";
 /* TEST DATA */
 rtems_id Semaphore_id;
 
-Objects_Locations location;   /* uses internal RTEMS type */
-
 Thread_Control *Middle_tcb;   /* uses internal RTEMS type */
 
 Thread_Control *Low_tcb;      /* uses internal RTEMS type */
@@ -517,7 +515,6 @@ void complete_test( void )
     for ( index=1 ; index <= OPERATION_COUNT ; index++ ) {
       (void) _Semaphore_Get_interrupt_disable(
         Semaphore_id,
-        &location,
         &lock_context
       );
       _ISR_lock_ISR_enable( &lock_context );
-- 
1.8.4.5




More information about the devel mailing list