Chromium Code Reviews| 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" |
| 11 #include "base/memory/discardable_shared_memory.h" | |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 13 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class DiscardableSharedMemory; | 18 class DiscardableSharedMemory; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 // Implements a heap of discardable shared memory. An array of free lists | 23 // Implements a heap of discardable shared memory. An array of free lists |
| 23 // is used to keep track of free blocks. | 24 // is used to keep track of free blocks. |
| 24 class CONTENT_EXPORT DiscardableSharedMemoryHeap { | 25 class CONTENT_EXPORT DiscardableSharedMemoryHeap { |
| 25 public: | 26 public: |
| 26 class CONTENT_EXPORT Span : public base::LinkNode<Span> { | 27 class CONTENT_EXPORT Span : public base::LinkNode<Span> { |
| 27 public: | 28 public: |
| 28 ~Span(); | 29 ~Span(); |
| 29 | 30 |
| 30 base::DiscardableSharedMemory* shared_memory() { return shared_memory_; } | 31 bool shared_memory() { return shared_memory_; } |
|
ssid
2015/09/29 16:03:55
I have also removed the getter here since it is no
| |
| 31 size_t start() const { return start_; } | 32 size_t start() const { return start_; } |
| 32 size_t length() const { return length_; } | 33 size_t length() const { return length_; } |
| 33 | 34 |
| 35 base::DiscardableSharedMemory::LockResult Lock(size_t page_size); | |
| 36 void Unlock(size_t page_size); | |
|
reveman
2015/09/29 22:58:31
I'd like to keep Span class as a simple container
| |
| 37 | |
| 38 // Returns true if shared_memory segment is resident. | |
| 39 bool IsMemoryResident() const; | |
| 40 | |
| 41 // Returns true if the span is locked by the client. | |
| 42 bool is_locked() { return is_locked_; } | |
| 43 | |
| 34 private: | 44 private: |
| 35 friend class DiscardableSharedMemoryHeap; | 45 friend class DiscardableSharedMemoryHeap; |
| 36 | 46 |
| 37 Span(base::DiscardableSharedMemory* shared_memory, | 47 Span(base::DiscardableSharedMemory* shared_memory, |
| 38 size_t start, | 48 size_t start, |
| 39 size_t length); | 49 size_t length, |
| 50 bool is_locked); | |
| 40 | 51 |
| 41 base::DiscardableSharedMemory* shared_memory_; | 52 base::DiscardableSharedMemory* shared_memory_; |
| 42 size_t start_; | 53 size_t start_; |
| 43 size_t length_; | 54 size_t length_; |
| 55 bool is_locked_; | |
| 44 | 56 |
| 45 DISALLOW_COPY_AND_ASSIGN(Span); | 57 DISALLOW_COPY_AND_ASSIGN(Span); |
| 46 }; | 58 }; |
| 47 | 59 |
| 48 explicit DiscardableSharedMemoryHeap(size_t block_size); | 60 explicit DiscardableSharedMemoryHeap(size_t block_size); |
| 49 ~DiscardableSharedMemoryHeap(); | 61 ~DiscardableSharedMemoryHeap(); |
| 50 | 62 |
| 51 // Grow heap using |shared_memory| and return a span for this new memory. | 63 // Grow heap using |shared_memory| and return a span for this new memory. |
| 52 // |shared_memory| must be aligned to the block size and |size| must be a | 64 // |shared_memory| must be aligned to the block size and |size| must be a |
| 53 // multiple of the block size. |deleted_callback| is called when | 65 // multiple of the block size. |deleted_callback| is called when |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // is a free list of runs that consist of k blocks. The 256th entry is a | 180 // is a free list of runs that consist of k blocks. The 256th entry is a |
| 169 // free list of runs that have length >= 256 blocks. | 181 // free list of runs that have length >= 256 blocks. |
| 170 base::LinkedList<Span> free_spans_[256]; | 182 base::LinkedList<Span> free_spans_[256]; |
| 171 | 183 |
| 172 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); | 184 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryHeap); |
| 173 }; | 185 }; |
| 174 | 186 |
| 175 } // namespace content | 187 } // namespace content |
| 176 | 188 |
| 177 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ | 189 #endif // CONTENT_COMMON_DISCARDABLE_SHARED_MEMORY_HEAP_H_ |
| OLD | NEW |