Skip to content

Commit

Permalink
Use std::chrono::steady_clock to handle backward system clock adjustm…
Browse files Browse the repository at this point in the history
…ents.
  • Loading branch information
PengZheng committed Dec 13, 2023
1 parent 8956987 commit 6e364bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libs/framework/include/celix/BundleActivator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ namespace impl {
template<typename T>
void waitForExpired(long bndId, std::weak_ptr<celix::BundleContext> &weakCtx, const char *name,
std::weak_ptr<T> &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<std::chrono::seconds>(now - start);
if (durationInSec > std::chrono::seconds{5}) {
auto msg = std::string{"Cannot destroy bundle "} + std::to_string(bndId) + ". " + name +
Expand Down
4 changes: 2 additions & 2 deletions libs/framework/include/celix/Trackers.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ namespace celix {

template<typename U>
void waitForExpired(std::weak_ptr<U> 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<std::chrono::milliseconds>(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());
Expand Down
4 changes: 2 additions & 2 deletions libs/framework/include/celix/dm/ServiceDependency_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ using namespace celix::dm;

template<typename U>
inline void BaseServiceDependency::waitForExpired(std::weak_ptr<U> 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<std::chrono::milliseconds>(now - start);
if (durationInMilli > warningTimoutForNonExpiredSvcObject) {
if (cCmp) {
Expand Down

0 comments on commit 6e364bb

Please sign in to comment.