Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains the implementation of the RingBuffer class. | 5 // This file contains the implementation of the RingBuffer class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/ring_buffer.h" | 7 #include "gpu/command_buffer/client/ring_buffer.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 in_use_offset_ = 0; | 139 in_use_offset_ = 0; |
| 140 free_offset_ = 0; | 140 free_offset_ = 0; |
| 141 } | 141 } |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 NOTREACHED() << "attempt to discard non-existant block"; | 145 NOTREACHED() << "attempt to discard non-existant block"; |
| 146 } | 146 } |
| 147 | 147 |
| 148 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { | 148 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { |
| 149 unsigned int last_token_read = helper_->last_token_read(); | |
| 150 while (!blocks_.empty()) { | 149 while (!blocks_.empty()) { |
| 151 Block& block = blocks_.front(); | 150 Block& block = blocks_.front(); |
| 152 if (block.token > last_token_read || block.state == IN_USE) break; | 151 if (!helper_->HasTokenPassed(block.token) || block.state == IN_USE) break; |
|
piman
2016/12/07 20:30:12
So, this would call GetLastState(), take the lock
sunnyps
2016/12/08 01:14:16
I made HasTokenPassed faster by using the cached t
| |
| 153 FreeOldestBlock(); | 152 FreeOldestBlock(); |
| 154 } | 153 } |
| 155 if (free_offset_ == in_use_offset_) { | 154 if (free_offset_ == in_use_offset_) { |
| 156 if (blocks_.empty()) { | 155 if (blocks_.empty()) { |
| 157 // The entire buffer is free. | 156 // The entire buffer is free. |
| 158 DCHECK_EQ(free_offset_, 0u); | 157 DCHECK_EQ(free_offset_, 0u); |
| 159 return size_; | 158 return size_; |
| 160 } else { | 159 } else { |
| 161 // The entire buffer is in use. | 160 // The entire buffer is in use. |
| 162 return 0; | 161 return 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 174 unsigned int largest_free_size = GetLargestFreeSizeNoWaiting(); | 173 unsigned int largest_free_size = GetLargestFreeSizeNoWaiting(); |
| 175 if (free_offset_ > in_use_offset_) { | 174 if (free_offset_ > in_use_offset_) { |
| 176 // It's free from free_offset_ to size_ and from 0 to in_use_offset_. | 175 // It's free from free_offset_ to size_ and from 0 to in_use_offset_. |
| 177 return size_ - free_offset_ + in_use_offset_; | 176 return size_ - free_offset_ + in_use_offset_; |
| 178 } else { | 177 } else { |
| 179 return largest_free_size; | 178 return largest_free_size; |
| 180 } | 179 } |
| 181 } | 180 } |
| 182 | 181 |
| 183 } // namespace gpu | 182 } // namespace gpu |
| OLD | NEW |