Fix problems caused by alignment.
The message was getting padded out to match alignment. This was
triggering the size that the user asked for to not match the size of the
message. These extra bytes were then getting coppied back into fetchers
and such.
We have 2 choices.
1) Waste the bytes at the end and keep the contract.
2) Modify the contract so that shm can store more bytes.
2) breaks the abstraction too much and causes too much change for a
negligable increase in storage, which pushes us to 1)
Change-Id: Idb3c79c93a7b7592628522b4304073f64bb06a2a
diff --git a/aos/ipc_lib/lockless_queue.cc b/aos/ipc_lib/lockless_queue.cc
index 0c87e4d..3fb506b 100644
--- a/aos/ipc_lib/lockless_queue.cc
+++ b/aos/ipc_lib/lockless_queue.cc
@@ -239,6 +239,12 @@
} // namespace
+size_t LocklessQueueConfiguration::message_size() const {
+ // Round up the message size so following data is aligned appropriately.
+ return LocklessQueueMemory::AlignmentRoundUp(message_data_size) +
+ sizeof(Message);
+}
+
size_t LocklessQueueMemorySize(LocklessQueueConfiguration config) {
// Round up the message size so following data is aligned appropriately.
config.message_data_size =
@@ -278,8 +284,7 @@
memory->config.num_watchers = config.num_watchers;
memory->config.num_senders = config.num_senders;
memory->config.queue_size = config.queue_size;
- memory->config.message_data_size =
- LocklessQueueMemory::AlignmentRoundUp(config.message_data_size);
+ memory->config.message_data_size = config.message_data_size;
const size_t num_messages = memory->num_messages();
// There need to be at most MaxMessages() messages allocated.
diff --git a/aos/ipc_lib/lockless_queue.h b/aos/ipc_lib/lockless_queue.h
index 4a8523b..d539386 100644
--- a/aos/ipc_lib/lockless_queue.h
+++ b/aos/ipc_lib/lockless_queue.h
@@ -83,7 +83,7 @@
// Size in bytes of the data stored in each Message.
size_t message_data_size;
- size_t message_size() const { return message_data_size + sizeof(Message); }
+ size_t message_size() const;
size_t num_messages() const { return num_senders + queue_size; }
};