Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 44 of file pointer_block.cc.

44: monitor_() {}

◆ ~BlockStack()

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

Definition at line 47 of file pointer_block.cc.

47 {
48 Reset();
49}

Member Function Documentation

◆ Cleanup()

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

Definition at line 38 of file pointer_block.cc.

38 {
39 delete global_empty_;
40 global_empty_ = nullptr;
41}
static List * global_empty_

◆ Init()

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

Definition at line 30 of file pointer_block.cc.

30 {
31 global_empty_ = new List();
32 if (global_mutex_ == nullptr) {
33 global_mutex_ = new Mutex();
34 }
35}
static Mutex * global_mutex_

◆ IsEmpty()

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

Definition at line 198 of file pointer_block.cc.

198 {
199 MonitorLocker ml(&monitor_);
200 return IsEmptyLocked();
201}

◆ IsEmptyLocked()

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

Definition at line 204 of file pointer_block.cc.

204 {
205 return full_.IsEmpty() && partial_.IsEmpty();
206}

◆ PopAll()

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

Definition at line 72 of file pointer_block.cc.

72 {
73 MonitorLocker ml(&monitor_);
74 while (!partial_.IsEmpty()) {
76 }
77 return full_.PopAll();
78}
void Push(Block *block)

◆ PopEmptyBlock()

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

Definition at line 174 of file pointer_block.cc.

174 {
175 {
176 MutexLocker ml(global_mutex_);
177 if (!global_empty_->IsEmpty()) {
178 return global_empty_->Pop();
179 }
180 }
181 return new Block();
182}
PointerBlock< BlockSize > Block

◆ PopNonEmptyBlock()

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

Definition at line 186 of file pointer_block.cc.

186 {
187 MonitorLocker ml(&monitor_);
188 if (!full_.IsEmpty()) {
189 return full_.Pop();
190 } else if (!partial_.IsEmpty()) {
191 return partial_.Pop();
192 } else {
193 return nullptr;
194 }
195}

◆ PopNonFullBlock()

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

Definition at line 163 of file pointer_block.cc.

163 {
164 {
165 MonitorLocker ml(&monitor_);
166 if (!partial_.IsEmpty()) {
167 return partial_.Pop();
168 }
169 }
170 return PopEmptyBlock();
171}
Block * PopEmptyBlock()

◆ PushAll()

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

Definition at line 81 of file pointer_block.cc.

81 {
82 while (block != nullptr) {
83 Block* next = block->next();
84 block->set_next(nullptr);
85 PushBlockImpl(block);
86 block = next;
87 }
88}
static float next(float f)
void PushBlockImpl(Block *block)

◆ PushBlockImpl()

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

Definition at line 91 of file pointer_block.cc.

91 {
92 ASSERT(block->next() == nullptr); // Should be just a single block.
93 if (block->IsFull()) {
94 MonitorLocker ml(&monitor_);
95 bool was_empty = IsEmptyLocked();
96 full_.Push(block);
97 if (was_empty) ml.Notify();
98 } else if (block->IsEmpty()) {
99 MutexLocker ml(global_mutex_);
100 global_empty_->Push(block);
102 } else {
103 MonitorLocker ml(&monitor_);
104 bool was_empty = IsEmptyLocked();
105 partial_.Push(block);
106 if (was_empty) ml.Notify();
107 }
108}
static void TrimGlobalEmpty()
#define ASSERT(E)

◆ Reset()

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

Definition at line 52 of file pointer_block.cc.

52 {
53 MonitorLocker local_mutex_locker(&monitor_);
54 {
55 // Empty all blocks and move them to the global cache.
56 MutexLocker global_mutex_locker(global_mutex_);
57 while (!full_.IsEmpty()) {
58 Block* block = full_.Pop();
59 block->Reset();
60 global_empty_->Push(block);
61 }
62 while (!partial_.IsEmpty()) {
63 Block* block = partial_.Pop();
64 block->Reset();
65 global_empty_->Push(block);
66 }
68 }
69}

◆ TrimGlobalEmpty()

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

Definition at line 262 of file pointer_block.cc.

262 {
265 delete global_empty_->Pop();
266 }
267}
#define DEBUG_ASSERT(cond)
Definition assert.h:321
intptr_t length() const
static constexpr intptr_t kMaxGlobalEmpty
bool IsOwnedByCurrentThread() const
Definition os_thread.h:401

◆ VisitObjectPointers()

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

Definition at line 251 of file pointer_block.cc.

251 {
252 for (Block* block = full_.Peek(); block != nullptr; block = block->next()) {
253 block->VisitObjectPointers(visitor);
254 }
255 for (Block* block = partial_.Peek(); block != nullptr;
256 block = block->next()) {
257 block->VisitObjectPointers(visitor);
258 }
259}
PointerBlock< Size > * next() const

◆ WaitForWork()

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

Definition at line 111 of file pointer_block.cc.

113 {
114 MonitorLocker ml(&monitor_);
115 if (num_busy->fetch_sub(1u) == 1 /* 1 is before subtraction */) {
116 // This is the last worker, wake the others now that we know no further work
117 // will come.
118 ml.NotifyAll();
119 return nullptr;
120 }
121 if (abort) {
122 return nullptr;
123 }
124 for (;;) {
125 if (!full_.IsEmpty()) {
126 num_busy->fetch_add(1u);
127 return full_.Pop();
128 }
129 if (!partial_.IsEmpty()) {
130 num_busy->fetch_add(1u);
131 return partial_.Pop();
132 }
133 ml.Wait();
134 if (num_busy->load() == 0) {
135 return nullptr;
136 }
137 }
138}
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: