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_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 Loading... |
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
_ |
OLD | NEW |