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

Side by Side Diff: mojo/services/media/common/cpp/shared_media_buffer_allocator.h

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
« no previous file with comments | « mojo/services/media/common/cpp/fifo_allocator.cc ('k') | services/media/framework/packet.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H_ 5 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H_
6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H_ 6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <mutex> // NOLINT(build/c++11) 9 #include <mutex> // NOLINT(build/c++11)
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 // Allocates a region of the buffer returning an offset. If the requested 30 // Allocates a region of the buffer returning an offset. If the requested
31 // region could not be allocated, returns kNullOffset. 31 // region could not be allocated, returns kNullOffset.
32 uint64_t AllocateRegionByOffset(uint64_t size) { 32 uint64_t AllocateRegionByOffset(uint64_t size) {
33 std::lock_guard<std::mutex> lock(lock_); 33 std::lock_guard<std::mutex> lock(lock_);
34 return fifo_allocator_.AllocateRegion(size); 34 return fifo_allocator_.AllocateRegion(size);
35 } 35 }
36 36
37 // Releases a region of the buffer previously allocated by calling 37 // Releases a region of the buffer previously allocated by calling
38 // AllocateRegionByOffset. 38 // AllocateRegionByOffset.
39 void ReleaseRegionByOffset(uint64_t size, uint64_t offset) { 39 void ReleaseRegionByOffset(uint64_t offset) {
40 std::lock_guard<std::mutex> lock(lock_); 40 std::lock_guard<std::mutex> lock(lock_);
41 fifo_allocator_.ReleaseRegion(size, offset); 41 fifo_allocator_.ReleaseRegion(offset);
42 } 42 }
43 43
44 // Allocates a region of the buffer returning a pointer. If the requested 44 // Allocates a region of the buffer returning a pointer. If the requested
45 // region could not be allocated, returns nullptr. 45 // region could not be allocated, returns nullptr.
46 void* AllocateRegion(uint64_t size) { 46 void* AllocateRegion(uint64_t size) {
47 return PtrFromOffset(AllocateRegionByOffset(size)); 47 return PtrFromOffset(AllocateRegionByOffset(size));
48 } 48 }
49 49
50 // Releases a region of the buffer previously allocated by calling 50 // Releases a region of the buffer previously allocated by calling
51 // AllocateRegion. 51 // AllocateRegion.
52 void ReleaseRegion(uint64_t size, void* ptr) { 52 void ReleaseRegion(void* ptr) {
53 ReleaseRegionByOffset(size, OffsetFromPtr(ptr)); 53 ReleaseRegionByOffset(OffsetFromPtr(ptr));
54 } 54 }
55 55
56 protected: 56 protected:
57 void OnInit() override; 57 void OnInit() override;
58 58
59 private: 59 private:
60 mutable std::mutex lock_; 60 mutable std::mutex lock_;
61 FifoAllocator fifo_allocator_; 61 FifoAllocator fifo_allocator_;
62 }; 62 };
63 63
64 } // namespace media 64 } // namespace media
65 } // namespace mojo 65 } // namespace mojo
66 66
67 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H _ 67 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_MEDIA_BUFFER_ALLOCATOR_H _
OLDNEW
« no previous file with comments | « mojo/services/media/common/cpp/fifo_allocator.cc ('k') | services/media/framework/packet.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698