Add the channel name into the sender creation failure message
It used to just fail saying "Too Many Senders". This isn't actionable.
We want the chanel name in there.
The fix is to propegate the failure up to the event loop where it can
make a more educated decision. Also, add a test (and make sure
simulation matches).
Change-Id: If70397ee319ad25ce5ab7ed146e8f5057d8af100
diff --git a/aos/ipc_lib/lockless_queue.h b/aos/ipc_lib/lockless_queue.h
index 550485f..de80f3d 100644
--- a/aos/ipc_lib/lockless_queue.h
+++ b/aos/ipc_lib/lockless_queue.h
@@ -5,6 +5,7 @@
#include <sys/signalfd.h>
#include <sys/types.h>
#include <vector>
+#include <optional>
#include "aos/ipc_lib/aos_sync.h"
#include "aos/ipc_lib/data_alignment.h"
@@ -245,6 +246,11 @@
Sender(LocklessQueueMemory *memory);
+ // Returns true if this sender is valid. If it isn't valid, any of the
+ // other methods won't work. This is here to allow the lockless queue to
+ // only build a sender if there was one available.
+ bool valid() const { return sender_index_ != -1 && memory_ != nullptr; }
+
// Pointer to the backing memory.
LocklessQueueMemory *memory_ = nullptr;
@@ -252,8 +258,9 @@
int sender_index_ = -1;
};
- // Creates a sender.
- Sender MakeSender();
+ // Creates a sender. If we couldn't allocate a sender, returns nullopt.
+ // TODO(austin): Change the API if we find ourselves with more errors.
+ std::optional<Sender> MakeSender();
private:
LocklessQueueMemory *memory_ = nullptr;