From 6e364bb705490256fda6a8bfb273bfaf372d00e3 Mon Sep 17 00:00:00 2001 From: PengZheng Date: Wed, 13 Dec 2023 17:36:54 +0800 Subject: [PATCH] Use std::chrono::steady_clock to handle backward system clock adjustments. --- libs/framework/include/celix/BundleActivator.h | 4 ++-- libs/framework/include/celix/Trackers.h | 4 ++-- libs/framework/include/celix/dm/ServiceDependency_Impl.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/framework/include/celix/BundleActivator.h b/libs/framework/include/celix/BundleActivator.h index 8fffadebe..17e0a3f9b 100644 --- a/libs/framework/include/celix/BundleActivator.h +++ b/libs/framework/include/celix/BundleActivator.h @@ -60,9 +60,9 @@ namespace impl { template void waitForExpired(long bndId, std::weak_ptr &weakCtx, const char *name, std::weak_ptr &observe) { - auto start = std::chrono::system_clock::now(); + auto start = std::chrono::steady_clock::now(); while (!observe.expired()) { - auto now = std::chrono::system_clock::now(); + auto now = std::chrono::steady_clock::now(); auto durationInSec = std::chrono::duration_cast(now - start); if (durationInSec > std::chrono::seconds{5}) { auto msg = std::string{"Cannot destroy bundle "} + std::to_string(bndId) + ". " + name + diff --git a/libs/framework/include/celix/Trackers.h b/libs/framework/include/celix/Trackers.h index d965ef54f..60df7c862 100644 --- a/libs/framework/include/celix/Trackers.h +++ b/libs/framework/include/celix/Trackers.h @@ -424,9 +424,9 @@ namespace celix { template void waitForExpired(std::weak_ptr observe, long svcId, const char* objName) { - auto start = std::chrono::system_clock::now(); + auto start = std::chrono::steady_clock::now(); while (!observe.expired()) { - auto now = std::chrono::system_clock::now(); + auto now = std::chrono::steady_clock::now(); auto durationInMilli = std::chrono::duration_cast(now - start); if (durationInMilli > warningTimoutForNonExpiredSvcObject) { celix_bundleContext_log(cCtx.get(), CELIX_LOG_LEVEL_WARNING, "Cannot remove %s associated with service.id %li, because it is still in use. Current shared_ptr use count is %i\n", objName, svcId, (int)observe.use_count()); diff --git a/libs/framework/include/celix/dm/ServiceDependency_Impl.h b/libs/framework/include/celix/dm/ServiceDependency_Impl.h index 7712bd835..297e81fcd 100644 --- a/libs/framework/include/celix/dm/ServiceDependency_Impl.h +++ b/libs/framework/include/celix/dm/ServiceDependency_Impl.h @@ -35,9 +35,9 @@ using namespace celix::dm; template inline void BaseServiceDependency::waitForExpired(std::weak_ptr observe, long svcId, const char* observeType) { - auto start = std::chrono::system_clock::now(); + auto start = std::chrono::steady_clock::now(); while (!observe.expired()) { - auto now = std::chrono::system_clock::now(); + auto now = std::chrono::steady_clock::now(); auto durationInMilli = std::chrono::duration_cast(now - start); if (durationInMilli > warningTimoutForNonExpiredSvcObject) { if (cCmp) {