Audacity 3.2.0
CancellationContext.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * SPDX-FileName: CancellationContext.h
4 * SPDX-FileContributor: Dmitry Vedenko
5 */
6
7#pragma once
8
9#include <atomic>
10#include <memory>
11#include <mutex>
12#include <vector>
13
15{
16class ICancellable;
17
18class CancellationContext;
19using CancellationContextPtr = std::shared_ptr<CancellationContext>;
20
21class CONCURRENCY_API CancellationContext final
22{
23 struct Tag final
24 {
25 };
26
27public:
28 explicit CancellationContext(Tag);
29
34
35 [[nodiscard]] static CancellationContextPtr Create();
36
37 void Cancel();
38
39 using CancellableWPtr = std::weak_ptr<ICancellable>;
40 void OnCancelled(CancellableWPtr cancellable);
41
42private:
43 std::atomic<bool> mCancelled { false };
44
46 std::vector<CancellableWPtr> mCancellableObjects;
47}; // struct CancellationContext
48} // namespace audacity::concurrency
CancellationContext(CancellationContext &&)=delete
std::weak_ptr< ICancellable > CancellableWPtr
CancellationContext & operator=(const CancellationContext &)=delete
CancellationContext & operator=(CancellationContext &&)=delete
CancellationContext(const CancellationContext &)=delete
std::vector< CancellableWPtr > mCancellableObjects
std::shared_ptr< CancellationContext > CancellationContextPtr