| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/store_buffer.h" | 5 #include "vm/store_buffer.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
| 9 #include "vm/runtime_entry.h" | 9 #include "vm/runtime_entry.h" |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 Isolate* isolate = Isolate::Current(); | 83 Isolate* isolate = Isolate::Current(); |
| 84 // Sanity check: it makes no sense to schedule the GC in another isolate. | 84 // Sanity check: it makes no sense to schedule the GC in another isolate. |
| 85 // (If Isolate ever gets multiple store buffers, we should avoid this | 85 // (If Isolate ever gets multiple store buffers, we should avoid this |
| 86 // coupling by passing in an explicit callback+parameter at construction.) | 86 // coupling by passing in an explicit callback+parameter at construction.) |
| 87 ASSERT(isolate->store_buffer() == this); | 87 ASSERT(isolate->store_buffer() == this); |
| 88 isolate->ScheduleInterrupts(Isolate::kVMInterrupt); | 88 isolate->ScheduleInterrupts(Isolate::kVMInterrupt); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 StoreBufferBlock* StoreBuffer::PopBlock() { | 93 StoreBufferBlock* StoreBuffer::PopNonFullBlock() { |
| 94 { | 94 { |
| 95 MutexLocker ml(mutex_); | 95 MutexLocker ml(mutex_); |
| 96 if (!partial_.IsEmpty()) { | 96 if (!partial_.IsEmpty()) { |
| 97 return partial_.Pop(); | 97 return partial_.Pop(); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return PopEmptyBlock(); | 100 return PopEmptyBlock(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 StoreBufferBlock* StoreBuffer::PopEmptyBlock() { | 104 StoreBufferBlock* StoreBuffer::PopEmptyBlock() { |
| 105 { | 105 { |
| 106 MutexLocker ml(global_mutex_); | 106 MutexLocker ml(global_mutex_); |
| 107 if (!global_empty_->IsEmpty()) { | 107 if (!global_empty_->IsEmpty()) { |
| 108 global_empty_->Pop(); | 108 global_empty_->Pop(); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 return new StoreBufferBlock(); | 111 return new StoreBufferBlock(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 StoreBufferBlock* StoreBuffer::PopNonEmptyBlock() { |
| 116 MutexLocker ml(mutex_); |
| 117 if (!full_.IsEmpty()) { |
| 118 return full_.Pop(); |
| 119 } else if (!partial_.IsEmpty()) { |
| 120 return partial_.Pop(); |
| 121 } else { |
| 122 return NULL; |
| 123 } |
| 124 } |
| 125 |
| 126 |
| 127 bool StoreBuffer::IsEmpty() { |
| 128 MutexLocker ml(global_mutex_); |
| 129 return full_.IsEmpty() && partial_.IsEmpty(); |
| 130 } |
| 131 |
| 132 |
| 115 StoreBuffer::List::~List() { | 133 StoreBuffer::List::~List() { |
| 116 while (!IsEmpty()) { | 134 while (!IsEmpty()) { |
| 117 delete Pop(); | 135 delete Pop(); |
| 118 } | 136 } |
| 119 } | 137 } |
| 120 | 138 |
| 121 | 139 |
| 122 StoreBufferBlock* StoreBuffer::List::Pop() { | 140 StoreBufferBlock* StoreBuffer::List::Pop() { |
| 123 StoreBufferBlock* result = head_; | 141 StoreBufferBlock* result = head_; |
| 124 head_ = head_->next_; | 142 head_ = head_->next_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 151 | 169 |
| 152 | 170 |
| 153 void StoreBuffer::TrimGlobalEmpty() { | 171 void StoreBuffer::TrimGlobalEmpty() { |
| 154 DEBUG_ASSERT(global_mutex_->IsOwnedByCurrentThread()); | 172 DEBUG_ASSERT(global_mutex_->IsOwnedByCurrentThread()); |
| 155 while (global_empty_->length() > kMaxGlobalEmpty) { | 173 while (global_empty_->length() > kMaxGlobalEmpty) { |
| 156 delete global_empty_->Pop(); | 174 delete global_empty_->Pop(); |
| 157 } | 175 } |
| 158 } | 176 } |
| 159 | 177 |
| 160 } // namespace dart | 178 } // namespace dart |
| OLD | NEW |