You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2021/11/21 14:01:11 UTC

[celix] branch master updated: Fix assertion failure when using C++ ServiceTracker in the event loop.

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/master by this push:
     new 64b7293  Fix assertion failure when using C++ ServiceTracker in the event loop.
     new 71fac23  Merge pull request #380 from PengZheng/fix-tracker-assertion
64b7293 is described below

commit 64b7293a133695566c2563b9c058d515ec4384df
Author: PengZheng <ho...@gmail.com>
AuthorDate: Tue Nov 16 20:07:59 2021 +0800

    Fix assertion failure when using C++ ServiceTracker in the event loop.
---
 libs/framework/gtest/src/CxxBundleContextTestSuite.cc | 16 +++++++++++++++-
 libs/framework/include/celix/Trackers.h               |  4 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
index d6ebe44..ff4a3c4 100644
--- a/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
+++ b/libs/framework/gtest/src/CxxBundleContextTestSuite.cc
@@ -550,6 +550,20 @@ TEST_F(CxxBundleContextTestSuite, UnregisterServiceWhileRegistering) {
     ctx->waitForEvents();
 }
 
+TEST_F(CxxBundleContextTestSuite, GetServiceInEventLoop) {
+    auto context = ctx;
+    ctx->getFramework()->fireGenericEvent(
+            ctx->getBundleId(),
+            "register/unregister in Celix event thread",
+            [context]() {
+                auto tracker = context->trackServices<TestInterface>().build();
+                auto svc = tracker->getHighestRankingService();
+                EXPECT_TRUE(svc.get() == nullptr);
+            }
+    );
+    ctx->waitForEvents();
+}
+
 TEST_F(CxxBundleContextTestSuite, KeepSharedPtrActiveWhileDeregistering) {
     auto svcReg = ctx->registerService<TestInterface>(std::make_shared<TestImplementation>())
             .build();
@@ -653,4 +667,4 @@ TEST_F(CxxBundleContextTestSuite, CheckStandardServiceProperties) {
     EXPECT_TRUE(called);
 
     celix_bundleContext_unregisterService(ctx->getCBundleContext(), svcId);
-}
\ No newline at end of file
+}
diff --git a/libs/framework/include/celix/Trackers.h b/libs/framework/include/celix/Trackers.h
index 5e8002a..d5339f9 100644
--- a/libs/framework/include/celix/Trackers.h
+++ b/libs/framework/include/celix/Trackers.h
@@ -159,7 +159,7 @@ namespace celix {
          */
         void waitIfAble() const {
             auto* fw = celix_bundleContext_getFramework(cCtx.get());
-            if (celix_framework_isCurrentThreadTheEventLoop(fw)) {
+            if (!celix_framework_isCurrentThreadTheEventLoop(fw)) {
                 wait();
             }
         }
@@ -765,4 +765,4 @@ namespace celix {
         const std::vector<std::function<void(const ServiceTrackerInfo&)>> onTrackerDestroyed;
     };
 
-}
\ No newline at end of file
+}