| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // previously locked range is undefined. | 67 // previously locked range is undefined. |
| 68 // |offset| and |length| must both be a multiple of the page size as returned | 68 // |offset| and |length| must both be a multiple of the page size as returned |
| 69 // by GetPageSize(). | 69 // by GetPageSize(). |
| 70 // Passing 0 for |length| means "everything onward". | 70 // Passing 0 for |length| means "everything onward". |
| 71 void Unlock(size_t offset, size_t length); | 71 void Unlock(size_t offset, size_t length); |
| 72 | 72 |
| 73 // Gets a pointer to the opened discardable memory space. Discardable memory | 73 // Gets a pointer to the opened discardable memory space. Discardable memory |
| 74 // must have been mapped via Map(). | 74 // must have been mapped via Map(). |
| 75 void* memory() const; | 75 void* memory() const; |
| 76 | 76 |
| 77 // Returns the last know usage time for DiscardableSharedMemory object. This | 77 // Returns the last known usage time for DiscardableSharedMemory object. This |
| 78 // may be earlier than the "true" usage time when memory has been used by a | 78 // may be earlier than the "true" usage time when memory has been used by a |
| 79 // different process. Returns NULL time if purged. | 79 // different process. Returns NULL time if purged. |
| 80 Time last_known_usage() const { return last_known_usage_; } | 80 Time last_known_usage() const { return last_known_usage_; } |
| 81 | 81 |
| 82 // This returns true and sets |last_known_usage_| to 0 if | 82 // This returns true and sets |last_known_usage_| to 0 if |
| 83 // DiscardableSharedMemory object was successfully purged. Purging can fail | 83 // DiscardableSharedMemory object was successfully purged. Purging can fail |
| 84 // for two reasons; object might be locked or our last known usage timestamp | 84 // for two reasons; object might be locked or our last known usage timestamp |
| 85 // might be out of date. Last known usage time is updated to |current_time| | 85 // might be out of date. Last known usage time is updated to |current_time| |
| 86 // if locked or the actual last usage timestamp if unlocked. It is often | 86 // if locked or the actual last usage timestamp if unlocked. It is often |
| 87 // neccesary to call this function twice for the object to successfully be | 87 // necessary to call this function twice for the object to successfully be |
| 88 // purged. First call, updates |last_known_usage_|. Second call, successfully | 88 // purged. First call, updates |last_known_usage_|. Second call, successfully |
| 89 // purges the object using the updated |last_known_usage_|. | 89 // purges the object using the updated |last_known_usage_|. |
| 90 // Note: there is no guarantee that multiple calls to this function will | 90 // Note: there is no guarantee that multiple calls to this function will |
| 91 // successfully purge object. DiscardableSharedMemory object might be locked | 91 // successfully purge object. DiscardableSharedMemory object might be locked |
| 92 // or another thread/process might be able to lock and unlock it in between | 92 // or another thread/process might be able to lock and unlock it in between |
| 93 // each call. | 93 // each call. |
| 94 bool Purge(Time current_time); | 94 bool Purge(Time current_time); |
| 95 | 95 |
| 96 // Purge and release as much memory as possible to the OS. | 96 // Purge and release as much memory as possible to the OS. |
| 97 // Note: The amount of memory that can be released to the OS is platform | 97 // Note: The amount of memory that can be released to the OS is platform |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // synchronized somehow. Use a collision warner to detect incorrect usage. | 130 // synchronized somehow. Use a collision warner to detect incorrect usage. |
| 131 DFAKE_MUTEX(thread_collision_warner_); | 131 DFAKE_MUTEX(thread_collision_warner_); |
| 132 Time last_known_usage_; | 132 Time last_known_usage_; |
| 133 | 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); | 134 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 } // namespace base | 137 } // namespace base |
| 138 | 138 |
| 139 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ | 139 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ |
| OLD | NEW |