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

pnoltes pushed a commit to branch feature/585-celix-conditions
in repository https://gitbox.apache.org/repos/asf/celix.git

commit d9e42903576015afb6593345bb0d7ad9386a6d5c
Merge: 1ace083c aeff793f
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue Jul 4 19:41:57 2023 +0200

    Merge branch 'feature/scheduled_event_on_event_thread' into 
feature/585-celix-conditions

 CMakeLists.txt                                     |  11 +-
 bundles/pubsub/pubsub_spi/CMakeLists.txt           |   2 +
 .../src/pubsub_topology_manager.c                  | 103 +++++++++-----
 .../src/pubsub_topology_manager.h                  |   9 +-
 bundles/pubsub/pubsub_utils/CMakeLists.txt         |   1 +
 .../include/endpoint_discovery_poller.h            |   3 +-
 .../src/endpoint_discovery_poller.c                |  67 +++++----
 .../discovery_shm/src/discovery_shmWatcher.c       |  51 ++++---
 .../discovery_zeroconf/gtest/CMakeLists.txt        |   2 +-
 .../rsa_shm/gtest/CMakeLists.txt                   |   2 +-
 bundles/remote_services/rsa_common/CMakeLists.txt  |  19 ++-
 .../rsa_common/gtest/CMakeLists.txt                |   2 +-
 .../remote_services/rsa_dfi_utils/CMakeLists.txt   |   1 +
 .../rsa_rpc_json/gtest/CMakeLists.txt              |   2 +-
 bundles/remote_services/thpool/CMakeLists.txt      |   2 +-
 cmake/CelixConfig.cmake                            |  49 ++-----
 cmake/CelixDeps.cmake.in                           |  13 ++
 documents/scheduled_events .md                     |   3 +-
 examples/CMakeLists.txt                            |   4 +-
 examples/celix-examples/CMakeLists.txt             |   5 +-
 libs/error_injector/CMakeLists.txt                 |   1 +
 libs/error_injector/stat/CMakeLists.txt            |   1 +
 libs/error_injector/stat/include/stat_ei.h         |   2 +
 libs/error_injector/stat/src/stat_ei.cc            |  17 ++-
 .../{unistd => stdlib}/CMakeLists.txt              |  12 +-
 .../unistd_ei.h => stdlib/include/stdlib_ei.h}     |  11 +-
 .../src/unistd_ei.cc => stdlib/src/stdlib_ei.cc}   |  19 +--
 libs/error_injector/unistd/CMakeLists.txt          |   6 +-
 libs/error_injector/unistd/include/unistd_ei.h     |   4 +
 libs/error_injector/unistd/src/unistd_ei.cc        |  23 +++-
 libs/framework/gtest/CMakeLists.txt                |   2 +
 libs/framework/gtest/config.properties.in          |   2 +-
 .../BundleArchiveWithErrorInjectionTestSuite.cc    |  43 ++++--
 .../src/CelixBundleContextBundlesTestSuite.cc      |  31 +++--
 .../CelixFrameworkUtilsErrorInjectionTestSuite.cc  |  26 ++++
 .../gtest/src/CelixFrameworkUtilsTestSuite.cc      |  32 ++++-
 libs/framework/include/celix/ScheduledEvent.h      |  24 +++-
 libs/framework/include/celix_bundle_context.h      |   4 +-
 libs/framework/include/celix_framework.h           |  14 +-
 libs/framework/include_deprecated/bundle_archive.h |   2 +-
 libs/framework/src/bundle_archive.c                |  51 ++++---
 libs/framework/src/bundle_archive_private.h        |   5 -
 libs/framework/src/celix_framework_utils.c         |  29 +++-
 libs/framework/src/celix_scheduled_event.c         |  51 +++----
 libs/framework/src/celix_scheduled_event.h         |  24 ++--
 libs/framework/src/framework.c                     | 153 ++++++++-------------
 libs/framework/src/framework_private.h             |  16 ++-
 libs/utils/gtest/src/ThreadsTestSuite.cc           |  14 +-
 libs/utils/gtest/src/TimeUtilsTestSuite.cc         |  24 ++++
 libs/utils/include/celix_threads.h                 |  11 +-
 libs/utils/include/celix_utils.h                   |   8 ++
 libs/utils/src/celix_threads.c                     |  18 ++-
 libs/utils/src/utils.c                             |  11 ++
 53 files changed, 638 insertions(+), 404 deletions(-)

diff --cc libs/framework/gtest/CMakeLists.txt
index ceac5a3f,1e78c447..225de605
--- a/libs/framework/gtest/CMakeLists.txt
+++ b/libs/framework/gtest/CMakeLists.txt
@@@ -154,7 -148,8 +154,9 @@@ if (LINKER_WRAP_SUPPORTED
              Celix::unistd_ei
              Celix::hash_map_ei
              Celix::properties_ei
+             Celix::stdlib_ei
+             Celix::stat_ei
 +            Celix::threads_ei
              GTest::gtest GTest::gtest_main
      )
  
diff --cc libs/framework/src/framework.c
index 88633507,9faf4465..745c4f51
--- a/libs/framework/src/framework.c
+++ b/libs/framework/src/framework.c
@@@ -1022,7 -968,8 +997,7 @@@ celix_status_t fw_removeFrameworkListen
          if (frameworkListener->listener == listener && 
frameworkListener->bundle == bundle) {
              arrayList_remove(framework->frameworkListeners, i);
  
-             
 -            frameworkListener->bundle = NULL;
 -            frameworkListener->listener = NULL;
++
              free(frameworkListener);
          }
      }
@@@ -1232,40 -1166,32 +1207,23 @@@ static void* framework_shutdown(void *f
      }
      celixThreadMutex_unlock(&fw->installedBundles.mutex);
  
 -
      size = celix_arrayList_size(stopEntries);
-     for (int i = size-1; i >= 0; --i) { //note loop in reverse order -> stop 
later installed bundle first
-         celix_framework_bundle_entry_t *entry = 
celix_arrayList_get(stopEntries, i);
- 
-         //NOTE possible starvation.
-         fw_bundleEntry_waitTillUseCountIs(entry, 1);  //note this function 
has 1 use count.
- 
-         //note race between condition (use count == 1) and bundle stop, 
meaning use count can be > 1 when
-         //celix_framework_stopBundleEntry is called.
- 
-         bundle_state_e state = celix_bundle_getState(entry->bnd);
-         if (state == CELIX_BUNDLE_STATE_ACTIVE || state == 
CELIX_BUNDLE_STATE_STARTING) {
-             celix_framework_stopBundleEntry(fw, entry);
-         }
-     }
      for (int i = size-1; i >= 0; --i) { //note loop in reverse order -> 
uninstall later installed bundle first
          celix_framework_bundle_entry_t *entry = 
celix_arrayList_get(stopEntries, i);
          celix_framework_uninstallBundleEntry(fw, entry, false);
      }
      celix_arrayList_destroy(stopEntries);
  
-     // 'stop' framework bundle
-     if (fwEntry != NULL) {
-         fw_bundleEntry_waitTillUseCountIs(fwEntry, 1); //note this function 
has 1 use count.
  
-         bundle_state_e state;
-         bundle_getState(fwEntry->bnd, &state);
-         if (state == CELIX_BUNDLE_STATE_ACTIVE || state == 
CELIX_BUNDLE_STATE_STARTING) {
-             celix_framework_stopBundleEntry(fw, fwEntry);
-         }
+     // make sure the framework has been stopped
+     if (fwEntry != NULL) {
+         // Lock the mutex to make sure that 
`celix_framework_stopBundleEntryInternal` on the framework has finished.
+         celixThreadRwlock_readLock(&fwEntry->fsmMutex);
+         celixThreadRwlock_unlock(&fwEntry->fsmMutex);
          celix_framework_bundleEntry_decreaseUseCount(fwEntry);
      }
--
+     //Now that all bundled has been stopped, no more events will be sent, we 
can safely stop the event dispatcher.
 -    //join dispatcher thread
 -    celixThreadMutex_lock(&fw->dispatcher.mutex);
 -    fw->dispatcher.active = false;
 -    celixThreadCondition_broadcast(&fw->dispatcher.cond);
 -    celixThreadMutex_unlock(&fw->dispatcher.mutex);
 -    celixThread_join(fw->dispatcher.thread, NULL);
 -    fw_log(fw->logger, CELIX_LOG_LEVEL_TRACE, "Joined event loop thread for 
framework %s", celix_framework_getUUID(framework));
 -
 +    celix_framework_stopAndJoinEventQueue(fw);
  
      celixThreadMutex_lock(&fw->shutdown.mutex);
      fw->shutdown.done = true;

Reply via email to