diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-03 12:57:16 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-04 07:24:29 +0200 |
commit | b1b6f3b0e0121d99014f5789c0275aa1b8639212 (patch) | |
tree | 77dae3046bf95a4d8a931b1b7de44cd06064c1f4 | |
parent | confdefs.h: Fix named object size estimate (diff) | |
download | rtems-b1b6f3b0e0121d99014f5789c0275aa1b8639212.tar.bz2 |
confdefs.h: Fix message queue size estimate
Account for maximum message size alignment. Simplify
_CORE_message_queue_Initialize().
-rw-r--r-- | cpukit/sapi/include/confdefs.h | 3 | ||||
-rw-r--r-- | cpukit/score/src/coremsg.c | 30 |
2 files changed, 15 insertions, 18 deletions
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h index e4e5331ef4..c32a902080 100644 --- a/cpukit/sapi/include/confdefs.h +++ b/cpukit/sapi/include/confdefs.h @@ -2978,7 +2978,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[]; */ #define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(_messages, _size) \ _Configure_From_workspace( \ - (_messages) * ((_size) + sizeof(CORE_message_queue_Buffer_control))) + (_messages) * (_Configure_Align_up(_size, sizeof(uintptr_t)) \ + + sizeof(CORE_message_queue_Buffer_control))) /** * This macro is set to the amount of memory required for pending message diff --git a/cpukit/score/src/coremsg.c b/cpukit/score/src/coremsg.c index 03c0587448..a3a0d76089 100644 --- a/cpukit/score/src/coremsg.c +++ b/cpukit/score/src/coremsg.c @@ -50,30 +50,26 @@ bool _CORE_message_queue_Initialize( ) { size_t message_buffering_required = 0; - size_t allocated_message_size; + size_t aligned_message_size; + size_t align_mask; 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 ); - allocated_message_size = maximum_message_size; - - /* - * Check if allocated_message_size is aligned to uintptr-size boundary. - * If not, it will increase allocated_message_size to multiplicity of pointer - * size. + /* + * Align up the maximum message size to be an integral multiple of the + * pointer size. */ - if (allocated_message_size & (sizeof(uintptr_t) - 1)) { - allocated_message_size += sizeof(uintptr_t); - allocated_message_size &= ~(sizeof(uintptr_t) - 1); - } + align_mask = sizeof(uintptr_t) - 1; + aligned_message_size = ( maximum_message_size + align_mask ) & ~align_mask; - /* - * Check for an overflow. It can occur while increasing allocated_message_size - * to multiplicity of uintptr_t above. + /* + * Check for an integer overflow. It can occur while aligning up the maximum + * message size. */ - if (allocated_message_size < maximum_message_size) + if (aligned_message_size < maximum_message_size) return false; /* @@ -82,7 +78,7 @@ bool _CORE_message_queue_Initialize( */ if ( !size_t_mult32_with_overflow( (size_t) maximum_pending_messages, - allocated_message_size + sizeof(CORE_message_queue_Buffer_control), + aligned_message_size + sizeof(CORE_message_queue_Buffer_control), &message_buffering_required ) ) return false; @@ -103,7 +99,7 @@ bool _CORE_message_queue_Initialize( &the_message_queue->Inactive_messages, the_message_queue->message_buffers, (size_t) maximum_pending_messages, - allocated_message_size + sizeof( CORE_message_queue_Buffer_control ) + aligned_message_size + sizeof( CORE_message_queue_Buffer_control ) ); _Chain_Initialize_empty( &the_message_queue->Pending_messages ); |