Skip to content

Commit ac74097

Browse files
Don't allow to cancel token again from itself (#1711)
Such recursions are possible in the complex nested CancellationContext scenarios Relates-To: OCMAM-783 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent e02c09f commit ac74097

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class CORE_API CancellationToken {
5151
void Cancel() const;
5252

5353
private:
54-
CancelFuncType func_;
54+
mutable CancelFuncType func_;
5555
};
5656

5757
} // namespace client

olp-cpp-sdk-core/src/client/CancellationToken.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,10 @@ CancellationToken::CancellationToken(CancelFuncType func)
2626
: func_(std::move(func)) {}
2727

2828
void CancellationToken::Cancel() const {
29-
if (func_) {
30-
func_();
29+
CancelFuncType func;
30+
std::swap(func_, func);
31+
if (func) {
32+
func();
3133
}
3234
}
3335

0 commit comments

Comments
 (0)