From 507d38261dd850ce6a572b8587a00eb3aa6c8bc6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 11 Sep 2009 20:00:30 +0000 Subject: 2009-09-11 Joel Sherrill * score/include/rtems/score/coremsg.h, score/inline/rtems/score/coremsg.inl, score/src/coremsg.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/objectnametoidstring.c: Disable the Core Message Queue features of notification, priority messages, and blocking sends when no API requires them. --- cpukit/score/src/coremsg.c | 4 +- cpukit/score/src/coremsginsert.c | 96 +++++++++++++++++++-------------- cpukit/score/src/coremsgseize.c | 79 ++++++++++++++++----------- cpukit/score/src/coremsgsubmit.c | 87 +++++++++++++++--------------- cpukit/score/src/objectnametoidstring.c | 2 +- 5 files changed, 151 insertions(+), 117 deletions(-) (limited to 'cpukit/score/src') diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c index 70638c0aec..b7448ab1fd 100644 --- a/cpukit/score/src/coremsg.c +++ b/cpukit/score/src/coremsg.c @@ -62,7 +62,9 @@ bool _CORE_message_queue_Initialize( the_message_queue->maximum_pending_messages = maximum_pending_messages; the_message_queue->number_of_pending_messages = 0; the_message_queue->maximum_message_size = maximum_message_size; - _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL ); + #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) + _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL ); + #endif /* * Round size up to multiple of a pointer for chain init and diff --git a/cpukit/score/src/coremsginsert.c b/cpukit/score/src/coremsginsert.c index 20d445efc7..9b5dbdfeef 100644 --- a/cpukit/score/src/coremsginsert.c +++ b/cpukit/score/src/coremsginsert.c @@ -56,59 +56,73 @@ void _CORE_message_queue_Insert_message( ) { ISR_Level level; - bool notify = false; + #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) + bool notify = false; + #define SET_NOTIFY() \ + if ( the_message_queue->number_of_pending_messages == 0 ) + notify = true; + #else + #define SET_NOTIFY() + #endif - the_message->priority = submit_type; + #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + the_message->priority = submit_type; + #endif - switch ( submit_type ) { - case CORE_MESSAGE_QUEUE_SEND_REQUEST: + #if !defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + _ISR_Disable( level ); + SET_NOTIFY(); + the_message_queue->number_of_pending_messages++; + if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) + _CORE_message_queue_Append_unprotected(the_message_queue, the_message); + else + _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message); + _ISR_Enable( level ); + #else + if ( submit_type == CORE_MESSAGE_QUEUE_SEND_REQUEST ) { _ISR_Disable( level ); - if ( the_message_queue->number_of_pending_messages++ == 0 ) - notify = true; + SET_NOTIFY(); + the_message_queue->number_of_pending_messages++; _CORE_message_queue_Append_unprotected(the_message_queue, the_message); _ISR_Enable( level ); - break; - case CORE_MESSAGE_QUEUE_URGENT_REQUEST: + } else if ( submit_type == CORE_MESSAGE_QUEUE_URGENT_REQUEST ) { _ISR_Disable( level ); - if ( the_message_queue->number_of_pending_messages++ == 0 ) - notify = true; + SET_NOTIFY(); + the_message_queue->number_of_pending_messages++; _CORE_message_queue_Prepend_unprotected(the_message_queue, the_message); _ISR_Enable( level ); - break; - default: - { - CORE_message_queue_Buffer_control *this_message; - Chain_Node *the_node; - Chain_Control *the_header; - - the_header = &the_message_queue->Pending_messages; - the_node = the_header->first; - while ( !_Chain_Is_tail( the_header, the_node ) ) { + } else { + CORE_message_queue_Buffer_control *this_message; + Chain_Node *the_node; + Chain_Control *the_header; - this_message = (CORE_message_queue_Buffer_control *) the_node; + the_header = &the_message_queue->Pending_messages; + the_node = the_header->first; + while ( !_Chain_Is_tail( the_header, the_node ) ) { - if ( this_message->priority <= the_message->priority ) { - the_node = the_node->next; - continue; - } + this_message = (CORE_message_queue_Buffer_control *) the_node; - break; + if ( this_message->priority <= the_message->priority ) { + the_node = the_node->next; + continue; } - _ISR_Disable( level ); - if ( the_message_queue->number_of_pending_messages++ == 0 ) - notify = true; - _Chain_Insert_unprotected( the_node->previous, &the_message->Node ); - _ISR_Enable( level ); + break; } - break; - } - - /* - * According to POSIX, does this happen before or after the message - * is actually enqueued. It is logical to think afterwards, because - * the message is actually in the queue at this point. - */ + _ISR_Disable( level ); + SET_NOTIFY(); + the_message_queue->number_of_pending_messages++; + _Chain_Insert_unprotected( the_node->previous, &the_message->Node ); + _ISR_Enable( level ); + } + #endif - if ( notify && the_message_queue->notify_handler ) - (*the_message_queue->notify_handler)( the_message_queue->notify_argument ); + #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) + /* + * According to POSIX, does this happen before or after the message + * is actually enqueued. It is logical to think afterwards, because + * the message is actually in the queue at this point. + */ + if ( notify && the_message_queue->notify_handler ) + (*the_message_queue->notify_handler)(the_message_queue->notify_argument); + #endif } diff --git a/cpukit/score/src/coremsgseize.c b/cpukit/score/src/coremsgseize.c index 8f736e97ae..e44dc80fda 100644 --- a/cpukit/score/src/coremsgseize.c +++ b/cpukit/score/src/coremsgseize.c @@ -68,7 +68,6 @@ void _CORE_message_queue_Seize( ISR_Level level; CORE_message_queue_Buffer_control *the_message; Thread_Control *executing; - Thread_Control *the_thread; executing = _Thread_Executing; executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; @@ -79,43 +78,61 @@ void _CORE_message_queue_Seize( _ISR_Enable( level ); *size_p = the_message->Contents.size; - _Thread_Executing->Wait.count = the_message->priority; + #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + _Thread_Executing->Wait.count = the_message->priority; + #endif _CORE_message_queue_Copy_buffer(the_message->Contents.buffer,buffer,*size_p); - /* - * There could be a thread waiting to send a message. If there - * is not, then we can go ahead and free the buffer. - * - * NOTE: If we note that the queue was not full before this receive, - * then we can avoid this dequeue. - */ - - the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); - if ( !the_thread ) { + #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND) + /* + * There is not an API with blocking sends enabled. So return immediately. + */ _CORE_message_queue_Free_message_buffer( the_message_queue, the_message ); return; - } + #else + { + Thread_Control *the_thread; - /* - * There was a thread waiting to send a message. This code - * puts the messages in the message queue on behalf of the - * waiting task. - */ + /* + * There could be a thread waiting to send a message. If there + * is not, then we can go ahead and free the buffer. + * + * NOTE: If we note that the queue was not full before this receive, + * then we can avoid this dequeue. + */ + the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); + if ( !the_thread ) { + _CORE_message_queue_Free_message_buffer( the_message_queue, the_message ); + return; + } - the_message->priority = the_thread->Wait.count; - the_message->Contents.size = (size_t) the_thread->Wait.option; - _CORE_message_queue_Copy_buffer( - the_thread->Wait.return_argument_second.immutable_object, - the_message->Contents.buffer, - the_message->Contents.size - ); + /* + * There was a thread waiting to send a message. This code + * puts the messages in the message queue on behalf of the + * waiting task. + */ + #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + the_message->priority = the_thread->Wait.count; + #endif + the_message->Contents.size = (size_t) the_thread->Wait.option; + _CORE_message_queue_Copy_buffer( + the_thread->Wait.return_argument_second.immutable_object, + the_message->Contents.buffer, + the_message->Contents.size + ); - _CORE_message_queue_Insert_message( - the_message_queue, - the_message, - the_message->priority - ); - return; + _CORE_message_queue_Insert_message( + the_message_queue, + the_message, + #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + the_message->priority, + #else + 0 + #endif + ); + return; + } + #endif } if ( !wait ) { diff --git a/cpukit/score/src/coremsgsubmit.c b/cpukit/score/src/coremsgsubmit.c index fbebdaa0b2..d52746e9ac 100644 --- a/cpukit/score/src/coremsgsubmit.c +++ b/cpukit/score/src/coremsgsubmit.c @@ -7,7 +7,7 @@ * This core object provides task synchronization and communication functions * via messages passed to queue objects. * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -69,7 +69,6 @@ CORE_message_queue_Status _CORE_message_queue_Submit( Watchdog_Interval timeout ) { - ISR_Level level; CORE_message_queue_Buffer_control *the_message; Thread_Control *the_thread; @@ -80,7 +79,6 @@ CORE_message_queue_Status _CORE_message_queue_Submit( /* * Is there a thread currently waiting on this message queue? */ - if ( the_message_queue->number_of_pending_messages == 0 ) { the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); if ( the_thread ) { @@ -104,7 +102,6 @@ CORE_message_queue_Status _CORE_message_queue_Submit( * No one waiting on the message queue at this time, so attempt to * queue the message up for a future receive. */ - if ( the_message_queue->number_of_pending_messages < the_message_queue->maximum_pending_messages ) { @@ -126,7 +123,9 @@ CORE_message_queue_Status _CORE_message_queue_Submit( size ); the_message->Contents.size = size; - the_message->priority = submit_type; + #if defined(RTEMS_SCORE_COREMSG_ENABLE_MESSAGE_PRIORITY) + the_message->priority = submit_type; + #endif _CORE_message_queue_Insert_message( the_message_queue, @@ -136,46 +135,48 @@ CORE_message_queue_Status _CORE_message_queue_Submit( return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; } - /* - * No message buffers were available so we may need to return an - * overflow error or block the sender until the message is placed - * on the queue. - */ - - if ( !wait ) { + #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND) return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY; - } - - /* - * Do NOT block on a send if the caller is in an ISR. It is - * deadly to block in an ISR. - */ - - if ( _ISR_Is_in_progress() ) { - return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; - } - - /* - * WARNING!! executing should NOT be used prior to this point. - * Thus the unusual choice to open a new scope and declare - * it as a variable. Doing this emphasizes how dangerous it - * would be to use this variable prior to here. - */ - - { - Thread_Control *executing = _Thread_Executing; + #else + /* + * No message buffers were available so we may need to return an + * overflow error or block the sender until the message is placed + * on the queue. + */ + if ( !wait ) { + return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY; + } - _ISR_Disable( level ); - _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue ); - executing->Wait.queue = &the_message_queue->Wait_queue; - executing->Wait.id = id; - executing->Wait.return_argument_second.immutable_object = buffer; - executing->Wait.option = (uint32_t) size; - executing->Wait.count = submit_type; - _ISR_Enable( level ); + /* + * Do NOT block on a send if the caller is in an ISR. It is + * deadly to block in an ISR. + */ + if ( _ISR_Is_in_progress() ) { + return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; + } - _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); - } + /* + * WARNING!! executing should NOT be used prior to this point. + * Thus the unusual choice to open a new scope and declare + * it as a variable. Doing this emphasizes how dangerous it + * would be to use this variable prior to here. + */ + { + Thread_Control *executing = _Thread_Executing; + ISR_Level level; + + _ISR_Disable( level ); + _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue ); + executing->Wait.queue = &the_message_queue->Wait_queue; + executing->Wait.id = id; + executing->Wait.return_argument_second.immutable_object = buffer; + executing->Wait.option = (uint32_t) size; + executing->Wait.count = submit_type; + _ISR_Enable( level ); + + _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); + } - return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT; + return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT; + #endif } diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c index 4d11d5d11a..71c7cc853f 100644 --- a/cpukit/score/src/objectnametoidstring.c +++ b/cpukit/score/src/objectnametoidstring.c @@ -16,7 +16,6 @@ #include "config.h" #endif -#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) #include #include @@ -31,6 +30,7 @@ #include #include +#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) /*PAGE * * _Objects_Name_to_id_string -- cgit v1.2.3