Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkIDChangeListener::List Class Reference

#include <SkIDChangeListener.h>

Public Member Functions

 List ()
 
 ~List ()
 
void add (sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
 
int count () const SK_EXCLUDES(fMutex)
 
void changed () SK_EXCLUDES(fMutex)
 
void reset () SK_EXCLUDES(fMutex)
 

Detailed Description

Manages a list of SkIDChangeListeners.

Definition at line 43 of file SkIDChangeListener.h.

Constructor & Destructor Documentation

◆ List()

List::List ( )
default

◆ ~List()

List::~List ( )

Definition at line 29 of file SkIDChangeListener.cpp.

29 {
30 // We don't need the mutex. No other thread should have this list while it's being
31 // destroyed.
32 for (auto& listener : fListeners) {
33 if (!listener->shouldDeregister()) {
34 listener->changed();
35 }
36 }
37}

Member Function Documentation

◆ add()

void List::add ( sk_sp< SkIDChangeListener listener)

Add a new listener to the list. It must not already be deregistered. Also clears out previously deregistered listeners.

Definition at line 39 of file SkIDChangeListener.cpp.

39 {
40 if (!listener) {
41 return;
42 }
43 SkASSERT(!listener->shouldDeregister());
44
45 SkAutoMutexExclusive lock(fMutex);
46 // Clean out any stale listeners before we append the new one.
47 for (int i = 0; i < fListeners.size(); ++i) {
48 if (fListeners[i]->shouldDeregister()) {
49 fListeners.removeShuffle(i--); // No need to preserve the order after i.
50 }
51 }
52 fListeners.push_back(std::move(listener));
53}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ changed()

void List::changed ( )

Calls changed() on all listeners that haven't been deregistered and resets the list.

Definition at line 60 of file SkIDChangeListener.cpp.

60 {
61 SkAutoMutexExclusive lock(fMutex);
62 for (auto& listener : fListeners) {
63 if (!listener->shouldDeregister()) {
64 listener->changed();
65 }
66 }
67 fListeners.clear();
68}

◆ count()

int List::count ( ) const

The number of registered listeners (including deregisterd listeners that are yet-to-be removed.

Definition at line 55 of file SkIDChangeListener.cpp.

55 {
56 SkAutoMutexExclusive lock(fMutex);
57 return fListeners.size();
58}

◆ reset()

void List::reset ( )

Resets without calling changed() on the listeners.

Definition at line 70 of file SkIDChangeListener.cpp.

70 {
71 SkAutoMutexExclusive lock(fMutex);
72 fListeners.clear();
73}

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