OLD | NEW |
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 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ | 5 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ |
6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ | 6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ |
7 | 7 |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // Resets the buffer manager to its initial state (no regions allocated) | 71 // Resets the buffer manager to its initial state (no regions allocated) |
72 // with a new buffer size. Also deletes all the regions in the lookaside. | 72 // with a new buffer size. Also deletes all the regions in the lookaside. |
73 void Reset(uint64_t size); | 73 void Reset(uint64_t size); |
74 | 74 |
75 // Allocates a region and returns its offset or kNullOffset if the allocation | 75 // Allocates a region and returns its offset or kNullOffset if the allocation |
76 // could not be performed. | 76 // could not be performed. |
77 uint64_t AllocateRegion(uint64_t size); | 77 uint64_t AllocateRegion(uint64_t size); |
78 | 78 |
79 // Releases a previously-allocated region. | 79 // Releases a previously-allocated region. |
80 void ReleaseRegion(uint64_t size, uint64_t offset); | 80 void ReleaseRegion(uint64_t offset); |
81 | 81 |
82 private: | 82 private: |
83 // List element to track allocated and free regions. | 83 // List element to track allocated and free regions. |
84 struct Region { | 84 struct Region { |
85 bool allocated; | 85 bool allocated; |
86 uint64_t size; | 86 uint64_t size; |
87 uint64_t offset; | 87 uint64_t offset; |
88 | 88 |
89 // Intrusive list pointers. | 89 // Intrusive list pointers. |
90 Region* prev; | 90 Region* prev; |
91 Region* next; | 91 Region* next; |
92 }; | 92 }; |
93 | 93 |
94 // Releases the specified region if it's found between begin (inclusive) and | 94 // Releases the specified region if it's found between begin (inclusive) and |
95 // end (exclusive). | 95 // end (exclusive). |
96 bool Release(uint64_t size, uint64_t offset, Region* begin, Region* end); | 96 bool Release(uint64_t offset, Region* begin, Region* end); |
97 | 97 |
98 // Advances the active region to one that's at least the specified size. | 98 // Advances the active region to one that's at least the specified size. |
99 // Returns false if none could be found. | 99 // Returns false if none could be found. |
100 bool AdvanceActive(uint64_t size); | 100 bool AdvanceActive(uint64_t size); |
101 | 101 |
102 // Does the above for the interval between begin (inclusive) and end | 102 // Does the above for the interval between begin (inclusive) and end |
103 // (exclusive). | 103 // (exclusive). |
104 bool AdvanceActive(uint64_t size, Region* begin, Region* end); | 104 bool AdvanceActive(uint64_t size, Region* begin, Region* end); |
105 | 105 |
106 // Inserts a zero-sized region after active_ and makes that the active region. | 106 // Inserts a zero-sized region after active_ and makes that the active region. |
(...skipping 29 matching lines...) Expand all Loading... |
136 Region* free_; | 136 Region* free_; |
137 | 137 |
138 // Unallocated region from which allocations are currently being made. | 138 // Unallocated region from which allocations are currently being made. |
139 Region* active_; | 139 Region* active_; |
140 }; | 140 }; |
141 | 141 |
142 } // namespace media | 142 } // namespace media |
143 } // namespace mojo | 143 } // namespace mojo |
144 | 144 |
145 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ | 145 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_FIFO_ALLOCATOR_H_ |
OLD | NEW |