Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion olp-cpp-sdk-core/include/olp/core/client/PendingRequests.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,8 @@ namespace client {
*/
class CORE_API PendingRequests final {
public:
~PendingRequests();

/**
* @brief Cancels all the pending tasks.
*
Expand Down
71 changes: 65 additions & 6 deletions olp-cpp-sdk-core/src/client/PendingRequests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,13 +29,25 @@
constexpr auto kLogTag = "PendingRequests";
}

PendingRequests::~PendingRequests() {
#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(kLogTag, "Destructor: pending task count=%zu, this=%p",
GetTaskCount(), static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL
}

bool PendingRequests::CancelAll() {
ContextMap contexts;
{
std::lock_guard<std::mutex> lock(task_contexts_lock_);
contexts = task_contexts_;
}

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(kLogTag, "CancelAll: pending task count=%zu, this=%p",
contexts.size(), static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL

for (auto context : contexts) {
context.CancelToken().Cancel();
}
Expand All @@ -52,23 +64,70 @@
contexts = std::move(task_contexts_);
}

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(
kLogTag, "CancelAllAndWait: started, pending task count=%zu, this=%p",
contexts.size(), static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL

for (auto context : contexts) {
if (!context.BlockingCancel()) {
OLP_SDK_LOG_WARNING(kLogTag, "Timeout, when waiting on BlockingCancel");
OLP_SDK_LOG_WARNING_F(kLogTag,

Check warning on line 75 in olp-cpp-sdk-core/src/client/PendingRequests.cpp

View check run for this annotation

Codecov / codecov/patch

olp-cpp-sdk-core/src/client/PendingRequests.cpp#L75

Added line #L75 was not covered by tests
"Timeout, when waiting on BlockingCancel, this=%p",
static_cast<void*>(this));
}
}

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(kLogTag, "CancelAllAndWait: finished, this=%p",
static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL

return true;
}

void PendingRequests::Insert(TaskContext task_context) {
std::lock_guard<std::mutex> lock(task_contexts_lock_);
task_contexts_.insert(task_context);
#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
size_t size = 0;
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL

{
std::lock_guard<std::mutex> lock(task_contexts_lock_);
task_contexts_.insert(task_context);

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
size = task_contexts_.size();
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL
}

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(
kLogTag,
"Insert: a new task context inserted. Pending task count=%zu, this=%p",
size, static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL
}

void PendingRequests::Remove(TaskContext task_context) {
std::lock_guard<std::mutex> lock(task_contexts_lock_);
task_contexts_.erase(task_context);
#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
size_t size = 0;
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL

{
std::lock_guard<std::mutex> lock(task_contexts_lock_);
task_contexts_.erase(task_context);

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
size = task_contexts_.size();
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL
}

#ifdef LOGGING_ENABLE_EXTENDED_INFO_LEVEL
OLP_SDK_LOG_INFO_F(
kLogTag,
"Remove: a task context removed. Pending task count=%zu, this=%p", size,
static_cast<void*>(this));
#endif // LOGGING_ENABLE_EXTENDED_INFO_LEVEL
}

size_t PendingRequests::GetTaskCount() const {
Expand Down