Change the event-loop restriction
It's weird but acceptable to create as many fetchers as you want.
RobotState is a common thing that multiple people want. We don't want
to support senders and watchers on the same loop (do you get your own
messages?) until there's a valid use case.
Change-Id: I215f452311d3f47ffd487d78885ae2848c6ffe9b
diff --git a/aos/events/shm-event-loop.cc b/aos/events/shm-event-loop.cc
index 945ebc0..781c963 100644
--- a/aos/events/shm-event-loop.cc
+++ b/aos/events/shm-event-loop.cc
@@ -1,12 +1,14 @@
#include "aos/events/shm-event-loop.h"
-#include "aos/logging/logging.h"
-#include "aos/queue.h"
#include <sys/timerfd.h>
+#include <algorithm>
#include <atomic>
#include <chrono>
#include <stdexcept>
+#include "aos/logging/logging.h"
+#include "aos/queue.h"
+
namespace aos {
ShmEventLoop::ShmEventLoop() : thread_state_(std::make_shared<ThreadState>()) {}
@@ -173,13 +175,13 @@
std::unique_ptr<RawFetcher> ShmEventLoop::MakeRawFetcher(
const std::string &path, const QueueTypeInfo &type) {
- Take(path);
return std::unique_ptr<RawFetcher>(new ShmFetcher(
RawQueue::Fetch(path.c_str(), type.size, type.hash, type.queue_length)));
}
std::unique_ptr<RawSender> ShmEventLoop::MakeRawSender(
const std::string &path, const QueueTypeInfo &type) {
+ Take(path);
return std::unique_ptr<RawSender>(new ShmSender(
RawQueue::Fetch(path.c_str(), type.size, type.hash, type.queue_length)));
}
@@ -269,8 +271,12 @@
if (is_running()) {
::aos::Die("Cannot add new objects while running.\n");
}
- if (!taken_.emplace(path).second) {
- ::aos::Die("%s already has a listener / watcher.", path.c_str());
+
+ const auto prior = ::std::find(taken_.begin(), taken_.end(), path);
+ if (prior != taken_.end()) {
+ ::aos::Die("%s is already being used.", path.c_str());
+ } else {
+ taken_.emplace_back(path);
}
}