| 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 BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ |
| 6 #define BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ | 6 #define BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 virtual ~DiscardableSharedMemory(); | 41 virtual ~DiscardableSharedMemory(); |
| 42 | 42 |
| 43 // Creates and maps a locked DiscardableSharedMemory object with |size|. | 43 // Creates and maps a locked DiscardableSharedMemory object with |size|. |
| 44 // Returns true on success and false on failure. | 44 // Returns true on success and false on failure. |
| 45 bool CreateAndMap(size_t size); | 45 bool CreateAndMap(size_t size); |
| 46 | 46 |
| 47 // Maps the locked discardable memory into the caller's address space. | 47 // Maps the locked discardable memory into the caller's address space. |
| 48 // Returns true on success, false otherwise. | 48 // Returns true on success, false otherwise. |
| 49 bool Map(size_t size); | 49 bool Map(size_t size); |
| 50 | 50 |
| 51 // Unmaps the discardable shared memory from the caller's address space. |
| 52 // Returns true if successful; returns false on error or if the memory is |
| 53 // not mapped. |
| 54 bool Unmap(); |
| 55 |
| 51 // The actual size of the mapped memory (may be larger than requested). | 56 // The actual size of the mapped memory (may be larger than requested). |
| 52 size_t mapped_size() const { return mapped_size_; } | 57 size_t mapped_size() const { return mapped_size_; } |
| 53 | 58 |
| 54 // Returns a shared memory handle for this DiscardableSharedMemory object. | 59 // Returns a shared memory handle for this DiscardableSharedMemory object. |
| 55 SharedMemoryHandle handle() const { return shared_memory_.handle(); } | 60 SharedMemoryHandle handle() const { return shared_memory_.handle(); } |
| 56 | 61 |
| 57 // Locks a range of memory so that it will not be purged by the system. | 62 // Locks a range of memory so that it will not be purged by the system. |
| 58 // The range of memory must be unlocked. The result of trying to lock an | 63 // The range of memory must be unlocked. The result of trying to lock an |
| 59 // already locked range is undefined. |offset| and |length| must both be | 64 // already locked range is undefined. |offset| and |length| must both be |
| 60 // a multiple of the page size as returned by GetPageSize(). | 65 // a multiple of the page size as returned by GetPageSize(). |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // synchronized somehow. Use a collision warner to detect incorrect usage. | 141 // synchronized somehow. Use a collision warner to detect incorrect usage. |
| 137 DFAKE_MUTEX(thread_collision_warner_); | 142 DFAKE_MUTEX(thread_collision_warner_); |
| 138 Time last_known_usage_; | 143 Time last_known_usage_; |
| 139 | 144 |
| 140 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); | 145 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); |
| 141 }; | 146 }; |
| 142 | 147 |
| 143 } // namespace base | 148 } // namespace base |
| 144 | 149 |
| 145 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ | 150 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ |
| OLD | NEW |