Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: mojo/services/media/common/cpp/fifo_allocator.cc

Issue 2081753002: Motown: Stop requiring size when releasing payload buffers. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "mojo/public/cpp/environment/logging.h" 5 #include "mojo/public/cpp/environment/logging.h"
6 #include "mojo/services/media/common/cpp/fifo_allocator.h" 6 #include "mojo/services/media/common/cpp/fifo_allocator.h"
7 7
8 namespace mojo { 8 namespace mojo {
9 namespace media { 9 namespace media {
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Create a new region (allocated) of the requested size at the front of the 60 // Create a new region (allocated) of the requested size at the front of the
61 // active region, and adjust the active region to reflect the deficit. 61 // active region, and adjust the active region to reflect the deficit.
62 MOJO_DCHECK(active_->size > size); 62 MOJO_DCHECK(active_->size > size);
63 Region* allocated = get_free(true, size, active_->offset); 63 Region* allocated = get_free(true, size, active_->offset);
64 active_->size -= size; 64 active_->size -= size;
65 active_->offset += size; 65 active_->offset += size;
66 insert_before(allocated, active_); 66 insert_before(allocated, active_);
67 return allocated->offset; 67 return allocated->offset;
68 } 68 }
69 69
70 void FifoAllocator::ReleaseRegion(uint64_t size, uint64_t offset) { 70 void FifoAllocator::ReleaseRegion(uint64_t offset) {
71 // Start at active_->next. That's usually the region we're looking for. 71 // Start at active_->next. That's usually the region we're looking for.
72 bool released = Release(size, offset, active_->next, nullptr) || 72 bool released = Release(offset, active_->next, nullptr) ||
73 Release(size, offset, front_, active_); 73 Release(offset, front_, active_);
74 MOJO_DCHECK(released); 74 MOJO_DCHECK(released);
75 } 75 }
76 76
77 bool FifoAllocator::Release(uint64_t size, 77 bool FifoAllocator::Release(uint64_t offset,
78 uint64_t offset,
79 Region* begin, 78 Region* begin,
80 Region* end) { 79 Region* end) {
81 MOJO_DCHECK(begin != nullptr || end == nullptr); 80 MOJO_DCHECK(begin != nullptr || end == nullptr);
82 for (Region* region = begin; region != end; region = region->next) { 81 for (Region* region = begin; region != end; region = region->next) {
83 if (region->offset == offset) { 82 if (region->offset == offset) {
84 MOJO_DCHECK(region->allocated); 83 MOJO_DCHECK(region->allocated);
85 MOJO_DCHECK(region->size == size);
86 region->allocated = false; 84 region->allocated = false;
87 85
88 Region* prev = region->prev; 86 Region* prev = region->prev;
89 if (prev != nullptr && !prev->allocated) { 87 if (prev != nullptr && !prev->allocated) {
90 // Coalesce wtih the previous region. 88 // Coalesce wtih the previous region.
91 prev->size += region->size; 89 prev->size += region->size;
92 remove(region); 90 remove(region);
93 put_free(region); 91 put_free(region);
94 region = prev; 92 region = prev;
95 } 93 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void FifoAllocator::DeleteFrontToBack(Region* region) { 207 void FifoAllocator::DeleteFrontToBack(Region* region) {
210 while (region != nullptr) { 208 while (region != nullptr) {
211 Region* to_delete = region; 209 Region* to_delete = region;
212 region = region->next; 210 region = region->next;
213 delete to_delete; 211 delete to_delete;
214 } 212 }
215 } 213 }
216 214
217 } // namespace media 215 } // namespace media
218 } // namespace mojo 216 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/media/common/cpp/fifo_allocator.h ('k') | mojo/services/media/common/cpp/shared_media_buffer_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698