summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-03 12:57:16 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-04 07:24:29 +0200
commitb1b6f3b0e0121d99014f5789c0275aa1b8639212 (patch)
tree77dae3046bf95a4d8a931b1b7de44cd06064c1f4 /cpukit/score
parentconfdefs.h: Fix named object size estimate (diff)
downloadrtems-b1b6f3b0e0121d99014f5789c0275aa1b8639212.tar.bz2
confdefs.h: Fix message queue size estimate
Account for maximum message size alignment. Simplify _CORE_message_queue_Initialize().
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/src/coremsg.c30
1 files changed, 13 insertions, 17 deletions
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 );