This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/split_celix_cxx_option in repository https://gitbox.apache.org/repos/asf/celix.git
commit b0e5c3dda0c05f4b6aea25f2af6720a96c7caa8b Author: Pepijn Noltes <[email protected]> AuthorDate: Sun Dec 4 17:05:49 2022 +0100 Fix coverity issue 236044 (uncaught exception in C++ RSA) The uncaught exception was a bug in the SharedPromiseState, which threw an exception if a promise was resolved more than one time. --- libs/promises/api/celix/impl/SharedPromiseState.h | 50 +++++++++++------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/libs/promises/api/celix/impl/SharedPromiseState.h b/libs/promises/api/celix/impl/SharedPromiseState.h index 78818e72..e3ee68cf 100644 --- a/libs/promises/api/celix/impl/SharedPromiseState.h +++ b/libs/promises/api/celix/impl/SharedPromiseState.h @@ -923,20 +923,19 @@ void celix::impl::SharedPromiseState<T>::complete(std::unique_lock<std::mutex>& if (!lck.owns_lock()) { lck.lock(); } - if (done) { - throw celix::PromiseInvocationException("Promise is already resolved"); - } - done = true; - cond.notify_all(); - while (!chain.empty()) { - std::vector<std::function<void()>> localChains{}; - localChains.swap(chain); - lck.unlock(); - for (auto &chainTask : localChains) { - executor->execute(priority, std::move(chainTask)); + if (!done) { + done = true; + cond.notify_all(); + while (!chain.empty()) { + std::vector<std::function<void()>> localChains{}; + localChains.swap(chain); + lck.unlock(); + for (auto &chainTask: localChains) { + executor->execute(priority, std::move(chainTask)); + } + localChains.clear(); + lck.lock(); } - localChains.clear(); - lck.lock(); } } @@ -944,19 +943,18 @@ inline void celix::impl::SharedPromiseState<void>::complete(std::unique_lock<std if (!lck.owns_lock()) { lck.lock(); } - if (done) { - throw celix::PromiseInvocationException("Promise is already resolved"); - } - done = true; - cond.notify_all(); - while (!chain.empty()) { - std::vector<std::function<void()>> localChains{}; - localChains.swap(chain); - lck.unlock(); - for (auto &chainTask : localChains) { - executor->execute(priority, std::move(chainTask)); + if (!done) { + done = true; + cond.notify_all(); + while (!chain.empty()) { + std::vector<std::function<void()>> localChains{}; + localChains.swap(chain); + lck.unlock(); + for (auto &chainTask: localChains) { + executor->execute(priority, std::move(chainTask)); + } + localChains.clear(); + lck.lock(); } - localChains.clear(); - lck.lock(); } } \ No newline at end of file
