Commit 9c995a82 authored by James Darpinian's avatar James Darpinian Committed by Commit Bot

gpu: Change CHECK to DCHECK in transfer buffer

As requested in the review of https://crrev.com/c/1336753. After
https://crbug.com/913996 is fixed we can remove
outstanding_result_pointer_ entirely when DCHECKs are disabled.

It also turns out that we can't use the string argument to ASSERT_DEATH
to detect a CHECK message in a test because the message strings are
stripped in official builds.

Bug: 905890, 913421, 913996
Change-Id: Ia7df19057564ef7a4bbbab9ba36f583c6e6bca0f
Reviewed-on: https://chromium-review.googlesource.com/c/1370484
Commit-Queue: James Darpinian <jdarpinian@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615680}
parent 3ee98b19
...@@ -153,7 +153,7 @@ void TransferBuffer::ReallocateRingBuffer(unsigned int size, bool shrink) { ...@@ -153,7 +153,7 @@ void TransferBuffer::ReallocateRingBuffer(unsigned int size, bool shrink) {
if (usable_ && (shrink || needed_buffer_size > current_size)) { if (usable_ && (shrink || needed_buffer_size > current_size)) {
// We should never attempt to reallocate the buffer if someone has a result // We should never attempt to reallocate the buffer if someone has a result
// pointer that hasn't been released. This would cause a use-after-free. // pointer that hasn't been released. This would cause a use-after-free.
CHECK(!outstanding_result_pointer_); DCHECK(!outstanding_result_pointer_);
if (HaveBuffer()) { if (HaveBuffer()) {
Free(); Free();
} }
...@@ -177,7 +177,7 @@ void TransferBuffer::ShrinkOrExpandRingBufferIfNecessary( ...@@ -177,7 +177,7 @@ void TransferBuffer::ShrinkOrExpandRingBufferIfNecessary(
unsigned int size_to_allocate) { unsigned int size_to_allocate) {
// We should never attempt to shrink the buffer if someone has a result // We should never attempt to shrink the buffer if someone has a result
// pointer that hasn't been released. // pointer that hasn't been released.
CHECK(!outstanding_result_pointer_); DCHECK(!outstanding_result_pointer_);
// Don't resize the buffer while blocks are in use to avoid throwing away // Don't resize the buffer while blocks are in use to avoid throwing away
// live allocations. // live allocations.
if (HaveBuffer() && ring_buffer_->NumUsedBlocks() > 0) if (HaveBuffer() && ring_buffer_->NumUsedBlocks() > 0)
...@@ -244,13 +244,17 @@ void* TransferBuffer::AcquireResultBuffer() { ...@@ -244,13 +244,17 @@ void* TransferBuffer::AcquireResultBuffer() {
// ensure this invariant. // ensure this invariant.
DCHECK(!outstanding_result_pointer_); DCHECK(!outstanding_result_pointer_);
ReallocateRingBuffer(result_size_); ReallocateRingBuffer(result_size_);
#if DCHECK_IS_ON()
outstanding_result_pointer_ = true; outstanding_result_pointer_ = true;
#endif
return result_buffer_; return result_buffer_;
} }
void TransferBuffer::ReleaseResultBuffer() { void TransferBuffer::ReleaseResultBuffer() {
DCHECK(outstanding_result_pointer_); DCHECK(outstanding_result_pointer_);
#if DCHECK_IS_ON()
outstanding_result_pointer_ = false; outstanding_result_pointer_ = false;
#endif
} }
int TransferBuffer::GetResultOffset() { int TransferBuffer::GetResultOffset() {
......
...@@ -742,7 +742,7 @@ TEST_F(TransferBufferTest, MultipleAllocsAndFrees) { ...@@ -742,7 +742,7 @@ TEST_F(TransferBufferTest, MultipleAllocsAndFrees) {
EXPECT_EQ(transfer_buffer_->GetFragmentedFreeSize(), original_free_size); EXPECT_EQ(transfer_buffer_->GetFragmentedFreeSize(), original_free_size);
} }
#if defined(GTEST_HAS_DEATH_TEST) #if defined(GTEST_HAS_DEATH_TEST) && DCHECK_IS_ON()
TEST_F(TransferBufferTest, ResizeDuringScopedResultPtr) { TEST_F(TransferBufferTest, ResizeDuringScopedResultPtr) {
Initialize(); Initialize();
...@@ -756,7 +756,6 @@ TEST_F(TransferBufferTest, ResizeDuringScopedResultPtr) { ...@@ -756,7 +756,6 @@ TEST_F(TransferBufferTest, ResizeDuringScopedResultPtr) {
"outstanding_result_pointer_"); "outstanding_result_pointer_");
} }
#if DCHECK_IS_ON()
TEST_F(TransferBufferTest, AllocDuringScopedResultPtr) { TEST_F(TransferBufferTest, AllocDuringScopedResultPtr) {
Initialize(); Initialize();
ScopedResultPtr<int> ptr(transfer_buffer_.get()); ScopedResultPtr<int> ptr(transfer_buffer_.get());
...@@ -776,7 +775,6 @@ TEST_F(TransferBufferTest, TwoScopedResultPtrs) { ...@@ -776,7 +775,6 @@ TEST_F(TransferBufferTest, TwoScopedResultPtrs) {
"outstanding_result_pointer_"); "outstanding_result_pointer_");
} }
#endif // DCHECK_IS_ON() #endif // defined(GTEST_HAS_DEATH_TEST) && DCHECK_IS_ON()
#endif // defined(GTEST_HAS_DEATH_TEST)
} // namespace gpu } // namespace gpu
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment