Index: c/src/exec/rtems/headers/message.h
===================================================================
--- c/src/exec/rtems/headers/message.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/headers/message.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -243,4 +243,21 @@
 
 /*
+ *  rtems_message_queue_get_number_pending
+ *
+ *  DESCRIPTION:
+ *
+ *  This routine implements the rtems_message_queue_get_number_pending
+ *  directive.  This directive returns the number of pending 
+ *  messages for the message queue indicated by ID 
+ *  chain.  The number of messages pending is returned in COUNT.
+ */
+
+rtems_status_code rtems_message_queue_get_number_pending(
+  Objects_Id  id,
+  unsigned32 *count
+);
+
+
+/*
  *  _Message_queue_Submit
  *
Index: c/src/exec/rtems/headers/msgmp.h
===================================================================
--- c/src/exec/rtems/headers/msgmp.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/headers/msgmp.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -35,17 +35,19 @@
 
 typedef enum {
-  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE     =  0,
-  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE     =  1,
-  MESSAGE_QUEUE_MP_EXTRACT_PROXY       =  2,
-  MESSAGE_QUEUE_MP_RECEIVE_REQUEST     =  3,
-  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE    =  4,
-  MESSAGE_QUEUE_MP_SEND_REQUEST        =  5,
-  MESSAGE_QUEUE_MP_SEND_RESPONSE       =  6,
-  MESSAGE_QUEUE_MP_URGENT_REQUEST      =  7,
-  MESSAGE_QUEUE_MP_URGENT_RESPONSE     =  8,
-  MESSAGE_QUEUE_MP_BROADCAST_REQUEST   =  9,
-  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE  = 10,
-  MESSAGE_QUEUE_MP_FLUSH_REQUEST       = 11,
-  MESSAGE_QUEUE_MP_FLUSH_RESPONSE      = 12
+  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE             =  0,
+  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE             =  1,
+  MESSAGE_QUEUE_MP_EXTRACT_PROXY               =  2,
+  MESSAGE_QUEUE_MP_RECEIVE_REQUEST             =  3,
+  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE            =  4,
+  MESSAGE_QUEUE_MP_SEND_REQUEST                =  5,
+  MESSAGE_QUEUE_MP_SEND_RESPONSE               =  6,
+  MESSAGE_QUEUE_MP_URGENT_REQUEST              =  7,
+  MESSAGE_QUEUE_MP_URGENT_RESPONSE             =  8,
+  MESSAGE_QUEUE_MP_BROADCAST_REQUEST           =  9,
+  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE          = 10,
+  MESSAGE_QUEUE_MP_FLUSH_REQUEST               = 11,
+  MESSAGE_QUEUE_MP_FLUSH_RESPONSE              = 12,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST  = 13,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE = 14
 }   Message_queue_MP_Remote_operations;
 
Index: c/src/exec/rtems/include/rtems/rtems/message.h
===================================================================
--- c/src/exec/rtems/include/rtems/rtems/message.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/include/rtems/rtems/message.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -243,4 +243,21 @@
 
 /*
+ *  rtems_message_queue_get_number_pending
+ *
+ *  DESCRIPTION:
+ *
+ *  This routine implements the rtems_message_queue_get_number_pending
+ *  directive.  This directive returns the number of pending 
+ *  messages for the message queue indicated by ID 
+ *  chain.  The number of messages pending is returned in COUNT.
+ */
+
+rtems_status_code rtems_message_queue_get_number_pending(
+  Objects_Id  id,
+  unsigned32 *count
+);
+
+
+/*
  *  _Message_queue_Submit
  *
Index: c/src/exec/rtems/include/rtems/rtems/msgmp.h
===================================================================
--- c/src/exec/rtems/include/rtems/rtems/msgmp.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/include/rtems/rtems/msgmp.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -35,17 +35,19 @@
 
 typedef enum {
-  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE     =  0,
-  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE     =  1,
-  MESSAGE_QUEUE_MP_EXTRACT_PROXY       =  2,
-  MESSAGE_QUEUE_MP_RECEIVE_REQUEST     =  3,
-  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE    =  4,
-  MESSAGE_QUEUE_MP_SEND_REQUEST        =  5,
-  MESSAGE_QUEUE_MP_SEND_RESPONSE       =  6,
-  MESSAGE_QUEUE_MP_URGENT_REQUEST      =  7,
-  MESSAGE_QUEUE_MP_URGENT_RESPONSE     =  8,
-  MESSAGE_QUEUE_MP_BROADCAST_REQUEST   =  9,
-  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE  = 10,
-  MESSAGE_QUEUE_MP_FLUSH_REQUEST       = 11,
-  MESSAGE_QUEUE_MP_FLUSH_RESPONSE      = 12
+  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE             =  0,
+  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE             =  1,
+  MESSAGE_QUEUE_MP_EXTRACT_PROXY               =  2,
+  MESSAGE_QUEUE_MP_RECEIVE_REQUEST             =  3,
+  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE            =  4,
+  MESSAGE_QUEUE_MP_SEND_REQUEST                =  5,
+  MESSAGE_QUEUE_MP_SEND_RESPONSE               =  6,
+  MESSAGE_QUEUE_MP_URGENT_REQUEST              =  7,
+  MESSAGE_QUEUE_MP_URGENT_RESPONSE             =  8,
+  MESSAGE_QUEUE_MP_BROADCAST_REQUEST           =  9,
+  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE          = 10,
+  MESSAGE_QUEUE_MP_FLUSH_REQUEST               = 11,
+  MESSAGE_QUEUE_MP_FLUSH_RESPONSE              = 12,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST  = 13,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE = 14
 }   Message_queue_MP_Remote_operations;
 
Index: c/src/exec/rtems/src/msg.c
===================================================================
--- c/src/exec/rtems/src/msg.c	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/src/msg.c	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -543,4 +543,54 @@
     case OBJECTS_LOCAL:
       *count = _CORE_message_queue_Flush( &the_message_queue->message_queue );
+      _Thread_Enable_dispatch();
+      return RTEMS_SUCCESSFUL;
+  }
+
+  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
+}
+
+/*PAGE
+ *
+ *  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(
+  Objects_Id  id,
+  unsigned32 *count
+)
+{
+  register Message_queue_Control *the_message_queue;
+  Objects_Locations               location;
+
+  the_message_queue = _Message_queue_Get( id, &location );
+  switch ( location ) {
+    case OBJECTS_ERROR:
+      return RTEMS_INVALID_ID;
+    case OBJECTS_REMOTE:
+      _Thread_Executing->Wait.return_argument = count;
+
+      return
+        _Message_queue_MP_Send_request_packet(
+          MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST,
+          id,
+          0,                               /* buffer not used */
+          0,                               /* size */
+          0,                               /* option_set not used */
+          MPCI_DEFAULT_TIMEOUT
+        );
+
+    case OBJECTS_LOCAL:
+      *count = the_message_queue->message_queue.number_of_pending_messages;
       _Thread_Enable_dispatch();
       return RTEMS_SUCCESSFUL;
Index: c/src/exec/rtems/src/msgmp.c
===================================================================
--- c/src/exec/rtems/src/msgmp.c	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ c/src/exec/rtems/src/msgmp.c	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -74,4 +74,6 @@
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
       break;
 
@@ -102,4 +104,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
 
       the_packet                    = _Message_queue_MP_Get_packet();
@@ -121,5 +124,5 @@
       }
 
-      if ( ! _Options_Is_no_wait(option_set))
+      if (! _Options_Is_no_wait(option_set))
           the_packet->Prefix.timeout = timeout;
 
@@ -155,5 +158,5 @@
       the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
 
-      if ( ! _Options_Is_no_wait(option_set))
+      if (! _Options_Is_no_wait(option_set))
           the_packet->Prefix.timeout = timeout;
 
@@ -181,4 +184,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
       break;
   }
@@ -208,4 +212,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
 
       the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet;
@@ -238,4 +243,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
       break;
 
@@ -285,5 +291,5 @@
       the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
 
-      if ( ! _Thread_Is_null( the_thread ) )
+      if (! _Thread_Is_null( the_thread ) )
          _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
 
@@ -301,5 +307,5 @@
       );
 
-      if ( ! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) )
+      if (! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) )
         _Message_queue_MP_Send_response_packet(
           MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
@@ -383,4 +389,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
 
       the_thread = _MPCI_Process_response( the_packet_prefix );
@@ -400,4 +407,18 @@
       _Message_queue_MP_Send_response_packet(
         MESSAGE_QUEUE_MP_FLUSH_RESPONSE,
+        the_packet->Prefix.id,
+        _Thread_Executing
+      );
+      break;
+
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+
+      the_packet->Prefix.return_code = rtems_message_queue_get_number_pending(
+        the_packet->Prefix.id,
+        &the_packet->count
+      );
+
+      _Message_queue_MP_Send_response_packet(
+        MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE,
         the_packet->Prefix.id,
         _Thread_Executing
Index: cpukit/rtems/include/rtems/rtems/message.h
===================================================================
--- cpukit/rtems/include/rtems/rtems/message.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ cpukit/rtems/include/rtems/rtems/message.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -243,4 +243,21 @@
 
 /*
+ *  rtems_message_queue_get_number_pending
+ *
+ *  DESCRIPTION:
+ *
+ *  This routine implements the rtems_message_queue_get_number_pending
+ *  directive.  This directive returns the number of pending 
+ *  messages for the message queue indicated by ID 
+ *  chain.  The number of messages pending is returned in COUNT.
+ */
+
+rtems_status_code rtems_message_queue_get_number_pending(
+  Objects_Id  id,
+  unsigned32 *count
+);
+
+
+/*
  *  _Message_queue_Submit
  *
Index: cpukit/rtems/include/rtems/rtems/msgmp.h
===================================================================
--- cpukit/rtems/include/rtems/rtems/msgmp.h	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ cpukit/rtems/include/rtems/rtems/msgmp.h	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -35,17 +35,19 @@
 
 typedef enum {
-  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE     =  0,
-  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE     =  1,
-  MESSAGE_QUEUE_MP_EXTRACT_PROXY       =  2,
-  MESSAGE_QUEUE_MP_RECEIVE_REQUEST     =  3,
-  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE    =  4,
-  MESSAGE_QUEUE_MP_SEND_REQUEST        =  5,
-  MESSAGE_QUEUE_MP_SEND_RESPONSE       =  6,
-  MESSAGE_QUEUE_MP_URGENT_REQUEST      =  7,
-  MESSAGE_QUEUE_MP_URGENT_RESPONSE     =  8,
-  MESSAGE_QUEUE_MP_BROADCAST_REQUEST   =  9,
-  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE  = 10,
-  MESSAGE_QUEUE_MP_FLUSH_REQUEST       = 11,
-  MESSAGE_QUEUE_MP_FLUSH_RESPONSE      = 12
+  MESSAGE_QUEUE_MP_ANNOUNCE_CREATE             =  0,
+  MESSAGE_QUEUE_MP_ANNOUNCE_DELETE             =  1,
+  MESSAGE_QUEUE_MP_EXTRACT_PROXY               =  2,
+  MESSAGE_QUEUE_MP_RECEIVE_REQUEST             =  3,
+  MESSAGE_QUEUE_MP_RECEIVE_RESPONSE            =  4,
+  MESSAGE_QUEUE_MP_SEND_REQUEST                =  5,
+  MESSAGE_QUEUE_MP_SEND_RESPONSE               =  6,
+  MESSAGE_QUEUE_MP_URGENT_REQUEST              =  7,
+  MESSAGE_QUEUE_MP_URGENT_RESPONSE             =  8,
+  MESSAGE_QUEUE_MP_BROADCAST_REQUEST           =  9,
+  MESSAGE_QUEUE_MP_BROADCAST_RESPONSE          = 10,
+  MESSAGE_QUEUE_MP_FLUSH_REQUEST               = 11,
+  MESSAGE_QUEUE_MP_FLUSH_RESPONSE              = 12,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST  = 13,
+  MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE = 14
 }   Message_queue_MP_Remote_operations;
 
Index: cpukit/rtems/src/msg.c
===================================================================
--- cpukit/rtems/src/msg.c	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ cpukit/rtems/src/msg.c	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -543,4 +543,54 @@
     case OBJECTS_LOCAL:
       *count = _CORE_message_queue_Flush( &the_message_queue->message_queue );
+      _Thread_Enable_dispatch();
+      return RTEMS_SUCCESSFUL;
+  }
+
+  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
+}
+
+/*PAGE
+ *
+ *  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(
+  Objects_Id  id,
+  unsigned32 *count
+)
+{
+  register Message_queue_Control *the_message_queue;
+  Objects_Locations               location;
+
+  the_message_queue = _Message_queue_Get( id, &location );
+  switch ( location ) {
+    case OBJECTS_ERROR:
+      return RTEMS_INVALID_ID;
+    case OBJECTS_REMOTE:
+      _Thread_Executing->Wait.return_argument = count;
+
+      return
+        _Message_queue_MP_Send_request_packet(
+          MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST,
+          id,
+          0,                               /* buffer not used */
+          0,                               /* size */
+          0,                               /* option_set not used */
+          MPCI_DEFAULT_TIMEOUT
+        );
+
+    case OBJECTS_LOCAL:
+      *count = the_message_queue->message_queue.number_of_pending_messages;
       _Thread_Enable_dispatch();
       return RTEMS_SUCCESSFUL;
Index: cpukit/rtems/src/msgmp.c
===================================================================
--- cpukit/rtems/src/msgmp.c	(revision a2fa8c2525453a0638cbb47acdade64189790bb2)
+++ cpukit/rtems/src/msgmp.c	(revision e7d8b5882699d0a44ab51c5547bbcd6b21d96b52)
@@ -74,4 +74,6 @@
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
       break;
 
@@ -102,4 +104,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
 
       the_packet                    = _Message_queue_MP_Get_packet();
@@ -121,5 +124,5 @@
       }
 
-      if ( ! _Options_Is_no_wait(option_set))
+      if (! _Options_Is_no_wait(option_set))
           the_packet->Prefix.timeout = timeout;
 
@@ -155,5 +158,5 @@
       the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
 
-      if ( ! _Options_Is_no_wait(option_set))
+      if (! _Options_Is_no_wait(option_set))
           the_packet->Prefix.timeout = timeout;
 
@@ -181,4 +184,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
       break;
   }
@@ -208,4 +212,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
 
       the_packet = ( Message_queue_MP_Packet *) the_thread->receive_packet;
@@ -238,4 +243,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_REQUEST:
     case MESSAGE_QUEUE_MP_FLUSH_REQUEST:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
       break;
 
@@ -285,5 +291,5 @@
       the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
 
-      if ( ! _Thread_Is_null( the_thread ) )
+      if (! _Thread_Is_null( the_thread ) )
          _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
 
@@ -301,5 +307,5 @@
       );
 
-      if ( ! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) )
+      if (! _Thread_Is_proxy_blocking( the_packet->Prefix.return_code ) )
         _Message_queue_MP_Send_response_packet(
           MESSAGE_QUEUE_MP_RECEIVE_RESPONSE,
@@ -383,4 +389,5 @@
     case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE:
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE:
 
       the_thread = _MPCI_Process_response( the_packet_prefix );
@@ -400,4 +407,18 @@
       _Message_queue_MP_Send_response_packet(
         MESSAGE_QUEUE_MP_FLUSH_RESPONSE,
+        the_packet->Prefix.id,
+        _Thread_Executing
+      );
+      break;
+
+    case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST:
+
+      the_packet->Prefix.return_code = rtems_message_queue_get_number_pending(
+        the_packet->Prefix.id,
+        &the_packet->count
+      );
+
+      _Message_queue_MP_Send_response_packet(
+        MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE,
         the_packet->Prefix.id,
         _Thread_Executing
