OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 5 #ifndef CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 6 #define CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/containers/linked_list.h" | 10 #include "base/containers/linked_list.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 // is used to keep track of free blocks. | 23 // is used to keep track of free blocks. |
24 class CONTENT_EXPORT DiscardableSharedMemoryHeap { | 24 class CONTENT_EXPORT DiscardableSharedMemoryHeap { |
25 public: | 25 public: |
26 class CONTENT_EXPORT Span : public base::LinkNode<Span> { | 26 class CONTENT_EXPORT Span : public base::LinkNode<Span> { |
27 public: | 27 public: |
28 ~Span(); | 28 ~Span(); |
29 | 29 |
30 base::DiscardableSharedMemory* shared_memory() { return shared_memory_; } | 30 base::DiscardableSharedMemory* shared_memory() { return shared_memory_; } |
31 size_t start() const { return start_; } | 31 size_t start() const { return start_; } |
32 size_t length() const { return length_; } | 32 size_t length() const { return length_; } |
33 void set_is_locked(bool is_locked) { is_locked_ = is_locked; } | |
34 | 33 |
35 private: | 34 private: |
36 friend class DiscardableSharedMemoryHeap; | 35 friend class DiscardableSharedMemoryHeap; |
37 | 36 |
38 Span(base::DiscardableSharedMemory* shared_memory, | 37 Span(base::DiscardableSharedMemory* shared_memory, |
39 size_t start, | 38 size_t start, |
40 size_t length); | 39 size_t length); |
41 | 40 |
42 base::DiscardableSharedMemory* shared_memory_; | 41 base::DiscardableSharedMemory* shared_memory_; |
43 size_t start_; | 42 size_t start_; |
44 size_t length_; | 43 size_t length_; |
45 bool is_locked_; | |
46 | 44 |
47 DISALLOW_COPY_AND_ASSIGN(Span); | 45 DISALLOW_COPY_AND_ASSIGN(Span); |
48 }; | 46 }; |
49 | 47 |
50 explicit DiscardableSharedMemoryHeap(size_t block_size); | 48 explicit DiscardableSharedMemoryHeap(size_t block_size); |
51 ~DiscardableSharedMemoryHeap(); | 49 ~DiscardableSharedMemoryHeap(); |
52 | 50 |
53 // Grow heap using |shared_memory| and return a span for this new memory. | 51 // Grow heap using |shared_memory| and return a span for this new memory. |
54 // |shared_memory| must be aligned to the block size and |size| must be a | 52 // |shared_memory| must be aligned to the block size and |size| must be a |
55 // multiple of the block size. |deleted_callback| is called when | 53 // multiple of the block size. |deleted_callback| is called when |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // is a free list of runs that consist of k blocks. The 256th entry is a | 168 // is a free list of runs that consist of k blocks. The 256th entry is a |
171 // free list of runs that have length >= 256 blocks. | 169 // free list of runs that have length >= 256 blocks. |
172 base::LinkedList<Span> free_spans_[256]; | 170 base::LinkedList<Span> free_spans_[256]; |
173 | 171 |
174 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); | 172 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); |
175 }; | 173 }; |
176 | 174 |
177 } // namespace content | 175 } // namespace content |
178 | 176 |
179 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 177 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
OLD | NEW |