Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
audacity::concurrency::CancellationContext Class Referencefinal

#include <CancellationContext.h>

Collaboration diagram for audacity::concurrency::CancellationContext:
[legend]

Classes

struct  Tag
 

Public Types

using CancellableWPtr = std::weak_ptr< ICancellable >
 

Public Member Functions

 CancellationContext (Tag)
 
 CancellationContext (const CancellationContext &)=delete
 
 CancellationContext (CancellationContext &&)=delete
 
CancellationContextoperator= (const CancellationContext &)=delete
 
CancellationContextoperator= (CancellationContext &&)=delete
 
void Cancel ()
 
void OnCancelled (CancellableWPtr cancellable)
 

Static Public Member Functions

static CancellationContextPtr Create ()
 

Private Attributes

std::atomic< bool > mCancelled { false }
 
std::mutex mCancellableObjectsMutex
 
std::vector< CancellableWPtrmCancellableObjects
 

Detailed Description

Definition at line 21 of file CancellationContext.h.

Member Typedef Documentation

◆ CancellableWPtr

Definition at line 39 of file CancellationContext.h.

Constructor & Destructor Documentation

◆ CancellationContext() [1/3]

audacity::concurrency::CancellationContext::CancellationContext ( Tag  )
explicit

Definition at line 15 of file CancellationContext.cpp.

16{
17}

◆ CancellationContext() [2/3]

audacity::concurrency::CancellationContext::CancellationContext ( const CancellationContext )
delete

◆ CancellationContext() [3/3]

audacity::concurrency::CancellationContext::CancellationContext ( CancellationContext &&  )
delete

Member Function Documentation

◆ Cancel()

void audacity::concurrency::CancellationContext::Cancel ( )

Definition at line 24 of file CancellationContext.cpp.

25{
26 if (mCancelled.exchange(true))
27 return;
28
29 std::vector<CancellableWPtr> cancellableObjects;
30
31 {
32 auto lock = std::lock_guard { mCancellableObjectsMutex };
33 std::swap(cancellableObjects, mCancellableObjects);
34 }
35
36 std::for_each(
37 cancellableObjects.begin(), cancellableObjects.end(),
38 [](auto& wptr)
39 {
40 if (auto lock = wptr.lock())
41 lock->Cancel();
42 });
43}
std::vector< CancellableWPtr > mCancellableObjects
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:628

References mCancellableObjects, mCancellableObjectsMutex, mCancelled, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ Create()

std::shared_ptr< CancellationContext > audacity::concurrency::CancellationContext::Create ( )
static

Definition at line 19 of file CancellationContext.cpp.

20{
21 return std::make_shared<CancellationContext>(Tag {});
22}

Referenced by audacity::cloud::audiocom::sync::MissingBlocksUploader::Create(), audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::Refresh(), audacity::cloud::audiocom::sync::DataUploader::Upload(), audacity::cloud::audiocom::sync::MixdownUploader::Upload(), and audacity::cloud::audiocom::sync::UploadMixdown().

Here is the caller graph for this function:

◆ OnCancelled()

void audacity::concurrency::CancellationContext::OnCancelled ( CancellableWPtr  cancellable)

Definition at line 45 of file CancellationContext.cpp.

46{
47 auto locked = cancellable.lock();
48 if (!locked)
49 return;
50
51 if (mCancelled.load(std::memory_order_acquire))
52 {
53 locked->Cancel();
54 return;
55 }
56
57 auto lock = std::lock_guard { mCancellableObjectsMutex };
59 std::remove_if(
61 [](auto& wptr) { return wptr.expired(); }),
63
64 mCancellableObjects.push_back(std::move(cancellable));
65}

References mCancellableObjects, mCancellableObjectsMutex, and mCancelled.

◆ operator=() [1/2]

CancellationContext & audacity::concurrency::CancellationContext::operator= ( CancellationContext &&  )
delete

◆ operator=() [2/2]

CancellationContext & audacity::concurrency::CancellationContext::operator= ( const CancellationContext )
delete

Member Data Documentation

◆ mCancellableObjects

std::vector<CancellableWPtr> audacity::concurrency::CancellationContext::mCancellableObjects
private

Definition at line 46 of file CancellationContext.h.

Referenced by Cancel(), and OnCancelled().

◆ mCancellableObjectsMutex

std::mutex audacity::concurrency::CancellationContext::mCancellableObjectsMutex
private

Definition at line 45 of file CancellationContext.h.

Referenced by Cancel(), and OnCancelled().

◆ mCancelled

std::atomic<bool> audacity::concurrency::CancellationContext::mCancelled { false }
private

Definition at line 43 of file CancellationContext.h.

Referenced by Cancel(), and OnCancelled().


The documentation for this class was generated from the following files: