[PATCH 09/19] rtems: Avoid Giant lock for message queues

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Apr 29 09:13:09 UTC 2016


Update #2555.
---
 cpukit/rtems/include/rtems/rtems/messageimpl.h | 21 ------------
 cpukit/rtems/src/msgqgetnumberpending.c        | 47 ++++++++++----------------
 2 files changed, 17 insertions(+), 51 deletions(-)

diff --git a/cpukit/rtems/include/rtems/rtems/messageimpl.h b/cpukit/rtems/include/rtems/rtems/messageimpl.h
index 3c904f0..46a4d9e 100644
--- a/cpukit/rtems/include/rtems/rtems/messageimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/messageimpl.h
@@ -101,27 +101,6 @@ RTEMS_INLINE_ROUTINE void _Message_queue_Free (
   _Objects_Free( &_Message_queue_Information, &the_message_queue->Object );
 }
 
-/**
- *  @brief Maps message queue IDs to message queue control blocks.
- *
- *  This function maps message queue IDs to message queue control
- *  blocks.  If ID corresponds to a local message queue, then it
- *  returns the_message_queue control pointer which maps to ID
- *  and location is set to OBJECTS_LOCAL.  If the message queue ID is
- *  global and resides on a remote node, then location is set
- *  to OBJECTS_REMOTE, and the_message_queue is undefined.
- *  Otherwise, location is set to OBJECTS_ERROR and
- *  the_message_queue is undefined.
- */
-RTEMS_INLINE_ROUTINE Message_queue_Control *_Message_queue_Get (
-  Objects_Id         id,
-  Objects_Locations *location
-)
-{
-  return (Message_queue_Control *)
-     _Objects_Get( &_Message_queue_Information, id, location );
-}
-
 RTEMS_INLINE_ROUTINE Message_queue_Control *
 _Message_queue_Get_interrupt_disable(
   Objects_Id         id,
diff --git a/cpukit/rtems/src/msgqgetnumberpending.c b/cpukit/rtems/src/msgqgetnumberpending.c
index ee058d8..756e8fe 100644
--- a/cpukit/rtems/src/msgqgetnumberpending.c
+++ b/cpukit/rtems/src/msgqgetnumberpending.c
@@ -18,55 +18,42 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/coremsgimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/wkspace.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/attrimpl.h>
 #include <rtems/rtems/messageimpl.h>
-#include <rtems/rtems/options.h>
-#include <rtems/rtems/support.h>
-
-/*
- *  rtems_message_queue_get_number_pending
- *
- *  This directive returns the number of messages pending.
- *
- *  Input parameters:
- *    id    - queue id
- *    count - return area for count
- *
- *  Output parameters:
- *    count             - number of messages removed ( 0 = empty queue )
- *    RTEMS_SUCCESSFUL - if successful
- *    error code        - if unsuccessful
- */
 
 rtems_status_code rtems_message_queue_get_number_pending(
   rtems_id  id,
   uint32_t *count
 )
 {
-  Message_queue_Control          *the_message_queue;
-  Objects_Locations               location;
+  Message_queue_Control *the_message_queue;
+  Objects_Locations      location;
+  ISR_lock_Context       lock_context;
 
   if ( !count )
     return RTEMS_INVALID_ADDRESS;
 
-  the_message_queue = _Message_queue_Get( id, &location );
+  the_message_queue = _Message_queue_Get_interrupt_disable(
+    id,
+    &location,
+    &lock_context
+  );
   switch ( location ) {
 
     case OBJECTS_LOCAL:
+      _CORE_message_queue_Acquire_critical(
+        &the_message_queue->message_queue,
+        &lock_context
+      );
       *count = the_message_queue->message_queue.number_of_pending_messages;
-      _Objects_Put( &the_message_queue->Object );
+      _CORE_message_queue_Release(
+        &the_message_queue->message_queue,
+        &lock_context
+      );
       return RTEMS_SUCCESSFUL;
 
 #if defined(RTEMS_MULTIPROCESSING)
     case OBJECTS_REMOTE:
-      _Thread_Executing->Wait.return_argument = count;
+      _Thread_Get_executing()->Wait.return_argument = count;
 
       return _Message_queue_MP_Send_request_packet(
           MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST,
-- 
1.8.4.5




More information about the devel mailing list