From 0d34eb904183b2945b05436d0ad79b4b4313cda8 Mon Sep 17 00:00:00 2001 From: Dawid Drozd Date: Mon, 28 Aug 2017 22:54:11 +0200 Subject: [PATCH] Fix nested transaction Quick fix for now. Probably we need better solution. --- include/eventbus/EventBus.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/eventbus/EventBus.h b/include/eventbus/EventBus.h index af0001a..2074f46 100644 --- a/include/eventbus/EventBus.h +++ b/include/eventbus/EventBus.h @@ -139,11 +139,11 @@ private: ContainerType container; ContainerType toAdd; std::vector toRemove; - bool inTransaction = false; + int inTransaction = 0; virtual void remove(const int token) override { - if (inTransaction) + if (inTransaction > 0) { toRemove.push_back(token); return; @@ -163,7 +163,7 @@ private: void add(const int token, const CallbackType& callback) { - if (inTransaction) + if (inTransaction > 0) { toAdd.emplace_back(token, callback); } @@ -175,12 +175,17 @@ private: void beginTransaction() { - inTransaction = true; + ++inTransaction; } void commitTransaction() { - inTransaction = false; + --inTransaction; + if (inTransaction > 0) + { + return; + } + inTransaction = 0; if (toAdd.empty() == false) {