Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
dart::BlockStack< BlockSize > Class Template Reference

#include <pointer_block.h>

Classes

class  List
 

Public Types

typedef PointerBlock< BlockSize > Block
 

Public Member Functions

 BlockStack ()
 
 ~BlockStack ()
 
BlockPopNonFullBlock ()
 
BlockPopEmptyBlock ()
 
BlockPopNonEmptyBlock ()
 
BlockPopAll ()
 
void PushAll (Block *blocks)
 
void Reset ()
 
bool IsEmpty ()
 
BlockWaitForWork (RelaxedAtomic< uintptr_t > *num_busy, bool abort)
 
void VisitObjectPointers (ObjectPointerVisitor *visitor)
 

Static Public Member Functions

static void Init ()
 
static void Cleanup ()
 

Protected Member Functions

bool IsEmptyLocked ()
 
void PushBlockImpl (Block *block)
 

Static Protected Member Functions

static void TrimGlobalEmpty ()
 

Protected Attributes

List full_
 
List partial_
 
Monitor monitor_
 

Static Protected Attributes

static constexpr intptr_t kMaxGlobalEmpty = 100
 
static Listglobal_empty_
 
static Mutexglobal_mutex_ = nullptr
 

Detailed Description

template<int BlockSize>
class dart::BlockStack< BlockSize >

Definition at line 89 of file pointer_block.h.

Member Typedef Documentation

◆ Block

template<int BlockSize>
typedef PointerBlock<BlockSize> dart::BlockStack< BlockSize >::Block

Definition at line 91 of file pointer_block.h.

Constructor & Destructor Documentation

◆ BlockStack()

template<int BlockSize>
dart::BlockStack< BlockSize >::BlockStack

Definition at line 55 of file pointer_block.cc.

55: monitor_() {}

◆ ~BlockStack()

template<int BlockSize>
dart::BlockStack< BlockSize >::~BlockStack

Definition at line 58 of file pointer_block.cc.

58 {
59 Reset();
60}

Member Function Documentation

◆ Cleanup()

template<int BlockSize>
void dart::BlockStack< BlockSize >::Cleanup
static

Definition at line 49 of file pointer_block.cc.

49 {
50 delete global_empty_;
51 global_empty_ = nullptr;
52}
static List * global_empty_

◆ Init()

template<int BlockSize>
void dart::BlockStack< BlockSize >::Init
static

Definition at line 41 of file pointer_block.cc.

41 {
42 global_empty_ = new List();
43 if (global_mutex_ == nullptr) {
44 global_mutex_ = new Mutex();
45 }
46}
SkIDChangeListener::List List
static Mutex * global_mutex_

◆ IsEmpty()

template<int BlockSize>
bool dart::BlockStack< BlockSize >::IsEmpty

Definition at line 209 of file pointer_block.cc.

209 {
210 MonitorLocker ml(&monitor_);
211 return IsEmptyLocked();
212}

◆ IsEmptyLocked()

template<int BlockSize>
bool dart::BlockStack< BlockSize >::IsEmptyLocked
protected

Definition at line 215 of file pointer_block.cc.

215 {
216 return full_.IsEmpty() && partial_.IsEmpty();
217}

◆ PopAll()

template<int BlockSize>
BlockStack< BlockSize >::Block * dart::BlockStack< BlockSize >::PopAll

Definition at line 83 of file pointer_block.cc.

83 {
84 MonitorLocker ml(&monitor_);
85 while (!partial_.IsEmpty()) {
87 }
88 return full_.PopAll();
89}
void Push(Block *block)

◆ PopEmptyBlock()

template<int BlockSize>
BlockStack< BlockSize >::Block * dart::BlockStack< BlockSize >::PopEmptyBlock

Definition at line 185 of file pointer_block.cc.

185 {
186 {
187 MutexLocker ml(global_mutex_);
188 if (!global_empty_->IsEmpty()) {
189 return global_empty_->Pop();
190 }
191 }
192 return new Block();
193}
PointerBlock< BlockSize > Block
Definition: pointer_block.h:91

◆ PopNonEmptyBlock()

template<int BlockSize>
BlockStack< BlockSize >::Block * dart::BlockStack< BlockSize >::PopNonEmptyBlock

Definition at line 197 of file pointer_block.cc.

197 {
198 MonitorLocker ml(&monitor_);
199 if (!full_.IsEmpty()) {
200 return full_.Pop();
201 } else if (!partial_.IsEmpty()) {
202 return partial_.Pop();
203 } else {
204 return nullptr;
205 }
206}

◆ PopNonFullBlock()

template<int BlockSize>
BlockStack< BlockSize >::Block * dart::BlockStack< BlockSize >::PopNonFullBlock

Definition at line 174 of file pointer_block.cc.

174 {
175 {
176 MonitorLocker ml(&monitor_);
177 if (!partial_.IsEmpty()) {
178 return partial_.Pop();
179 }
180 }
181 return PopEmptyBlock();
182}
Block * PopEmptyBlock()

◆ PushAll()

template<int BlockSize>
void dart::BlockStack< BlockSize >::PushAll ( Block blocks)

Definition at line 92 of file pointer_block.cc.

92 {
93 while (block != nullptr) {
94 Block* next = block->next();
95 block->set_next(nullptr);
96 PushBlockImpl(block);
97 block = next;
98 }
99}
static float next(float f)
void PushBlockImpl(Block *block)

◆ PushBlockImpl()

template<int BlockSize>
void dart::BlockStack< BlockSize >::PushBlockImpl ( Block block)
protected

Definition at line 102 of file pointer_block.cc.

102 {
103 ASSERT(block->next() == nullptr); // Should be just a single block.
104 if (block->IsFull()) {
105 MonitorLocker ml(&monitor_);
106 bool was_empty = IsEmptyLocked();
107 full_.Push(block);
108 if (was_empty) ml.Notify();
109 } else if (block->IsEmpty()) {
110 MutexLocker ml(global_mutex_);
111 global_empty_->Push(block);
113 } else {
114 MonitorLocker ml(&monitor_);
115 bool was_empty = IsEmptyLocked();
116 partial_.Push(block);
117 if (was_empty) ml.Notify();
118 }
119}
static void TrimGlobalEmpty()
#define ASSERT(E)

◆ Reset()

template<int BlockSize>
void dart::BlockStack< BlockSize >::Reset

Definition at line 63 of file pointer_block.cc.

63 {
64 MonitorLocker local_mutex_locker(&monitor_);
65 {
66 // Empty all blocks and move them to the global cache.
67 MutexLocker global_mutex_locker(global_mutex_);
68 while (!full_.IsEmpty()) {
69 Block* block = full_.Pop();
70 block->Reset();
71 global_empty_->Push(block);
72 }
73 while (!partial_.IsEmpty()) {
74 Block* block = partial_.Pop();
75 block->Reset();
76 global_empty_->Push(block);
77 }
79 }
80}

◆ TrimGlobalEmpty()

template<int BlockSize>
void dart::BlockStack< BlockSize >::TrimGlobalEmpty
staticprotected

Definition at line 273 of file pointer_block.cc.

273 {
276 delete global_empty_->Pop();
277 }
278}
#define DEBUG_ASSERT(cond)
Definition: assert.h:321
intptr_t length() const
static constexpr intptr_t kMaxGlobalEmpty
bool IsOwnedByCurrentThread() const
Definition: os_thread.h:402

◆ VisitObjectPointers()

template<int BlockSize>
void dart::BlockStack< BlockSize >::VisitObjectPointers ( ObjectPointerVisitor visitor)

Definition at line 262 of file pointer_block.cc.

262 {
263 for (Block* block = full_.Peek(); block != nullptr; block = block->next()) {
264 block->VisitObjectPointers(visitor);
265 }
266 for (Block* block = partial_.Peek(); block != nullptr;
267 block = block->next()) {
268 block->VisitObjectPointers(visitor);
269 }
270}
PointerBlock< Size > * next() const
Definition: pointer_block.h:30

◆ WaitForWork()

template<int BlockSize>
BlockStack< BlockSize >::Block * dart::BlockStack< BlockSize >::WaitForWork ( RelaxedAtomic< uintptr_t > *  num_busy,
bool  abort 
)

Definition at line 122 of file pointer_block.cc.

124 {
125 MonitorLocker ml(&monitor_);
126 if (num_busy->fetch_sub(1u) == 1 /* 1 is before subtraction */) {
127 // This is the last worker, wake the others now that we know no further work
128 // will come.
129 ml.NotifyAll();
130 return nullptr;
131 }
132 if (abort) {
133 return nullptr;
134 }
135 for (;;) {
136 if (!full_.IsEmpty()) {
137 num_busy->fetch_add(1u);
138 return full_.Pop();
139 }
140 if (!partial_.IsEmpty()) {
141 num_busy->fetch_add(1u);
142 return partial_.Pop();
143 }
144 ml.Wait();
145 if (num_busy->load() == 0) {
146 return nullptr;
147 }
148 }
149}
T load(std::memory_order order=std::memory_order_relaxed) const
Definition: atomic.h:21
T fetch_add(T arg, std::memory_order order=std::memory_order_relaxed)
Definition: atomic.h:35
T fetch_sub(T arg, std::memory_order order=std::memory_order_relaxed)
Definition: atomic.h:38

Member Data Documentation

◆ full_

template<int BlockSize>
List dart::BlockStack< BlockSize >::full_
protected

Definition at line 144 of file pointer_block.h.

◆ global_empty_

template<int BlockSize>
END_LEAF_RUNTIME_ENTRY BlockStack< BlockSize >::List * dart::BlockStack< BlockSize >::global_empty_
staticprotected
Initial value:
=
nullptr

Definition at line 150 of file pointer_block.h.

◆ global_mutex_

template<int BlockSize>
Mutex * dart::BlockStack< BlockSize >::global_mutex_ = nullptr
staticprotected

Definition at line 151 of file pointer_block.h.

◆ kMaxGlobalEmpty

template<int BlockSize>
constexpr intptr_t dart::BlockStack< BlockSize >::kMaxGlobalEmpty = 100
staticconstexprprotected

Definition at line 149 of file pointer_block.h.

◆ monitor_

template<int BlockSize>
Monitor dart::BlockStack< BlockSize >::monitor_
protected

Definition at line 146 of file pointer_block.h.

◆ partial_

template<int BlockSize>
List dart::BlockStack< BlockSize >::partial_
protected

Definition at line 145 of file pointer_block.h.


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