@@ -7,14 +7,14 @@ namespace plugify {
77 class SimpleEventBus final : public IEventBus {
88 public:
99 SubscriptionId Subscribe (std::string_view eventType, EventHandler handler) override {
10- std::lock_guard lock (_mutex);
10+ std::unique_lock lock (_mutex);
1111 auto id = _nextId++;
1212 _handlers[std::string (eventType)].emplace_back (id, std::move (handler));
1313 return id;
1414 }
1515
1616 void Unsubscribe (SubscriptionId id) override {
17- std::lock_guard lock (_mutex);
17+ std::unique_lock lock (_mutex);
1818 for (auto & [_, handlers] : _handlers) {
1919 handlers.erase (
2020 std::remove_if (
@@ -31,7 +31,7 @@ namespace plugify {
3131 std::vector<EventHandler> handlersToCall;
3232
3333 {
34- std::lock_guard lock (_mutex);
34+ std::shared_lock lock (_mutex);
3535 auto it = _handlers.find (eventType);
3636 if (it != _handlers.end ()) {
3737 for (const auto & [_, handler] : it->second ) {
@@ -47,7 +47,7 @@ namespace plugify {
4747 }
4848
4949 private:
50- mutable std::mutex _mutex;
50+ mutable std::shared_mutex _mutex;
5151 std::unordered_map<
5252 std::string,
5353 std::vector<std::pair<SubscriptionId, EventHandler>>,
0 commit comments