Account for maximum message size alignment. Simplify _CORE_message_queue_Initialize(). --- cpukit/sapi/include/confdefs.h | 3 ++- 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 e4e5331..c32a902 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 03c0587..a3a0d76 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 ); -- 1.8.4.5 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel