Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: base/memory/discardable_shared_memory.h

Issue 1018743003: Re-land: base: Replace PurgeAndTruncate with Shrink function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: avoid using ftruncate on android Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 27
28 DiscardableSharedMemory(); 28 DiscardableSharedMemory();
29 29
30 // Create a new DiscardableSharedMemory object from an existing, open shared 30 // Create a new DiscardableSharedMemory object from an existing, open shared
31 // memory file. Memory must be locked. 31 // memory file. Memory must be locked.
32 explicit DiscardableSharedMemory(SharedMemoryHandle handle); 32 explicit DiscardableSharedMemory(SharedMemoryHandle handle);
33 33
34 // Closes any open files. 34 // Closes any open files.
35 virtual ~DiscardableSharedMemory(); 35 virtual ~DiscardableSharedMemory();
36 36
37 // Return true iff shrinking of discardable shared memory is supported.
38 static bool IsShrinkingSupported();
39
37 // Creates and maps a locked DiscardableSharedMemory object with |size|. 40 // Creates and maps a locked DiscardableSharedMemory object with |size|.
38 // Returns true on success and false on failure. 41 // Returns true on success and false on failure.
39 bool CreateAndMap(size_t size); 42 bool CreateAndMap(size_t size);
40 43
41 // Maps the locked discardable memory into the caller's address space. 44 // Maps the locked discardable memory into the caller's address space.
42 // Returns true on success, false otherwise. 45 // Returns true on success, false otherwise.
43 bool Map(size_t size); 46 bool Map(size_t size);
44 47
45 // The actual size of the mapped memory (may be larger than requested). 48 // The actual size of the mapped memory (may be larger than requested).
46 size_t mapped_size() const { return mapped_size_; } 49 size_t mapped_size() const { return mapped_size_; }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // if locked or the actual last usage timestamp if unlocked. It is often 89 // if locked or the actual last usage timestamp if unlocked. It is often
87 // necessary to call this function twice for the object to successfully be 90 // necessary to call this function twice for the object to successfully be
88 // purged. First call, updates |last_known_usage_|. Second call, successfully 91 // purged. First call, updates |last_known_usage_|. Second call, successfully
89 // purges the object using the updated |last_known_usage_|. 92 // purges the object using the updated |last_known_usage_|.
90 // Note: there is no guarantee that multiple calls to this function will 93 // Note: there is no guarantee that multiple calls to this function will
91 // successfully purge object. DiscardableSharedMemory object might be locked 94 // successfully purge object. DiscardableSharedMemory object might be locked
92 // or another thread/process might be able to lock and unlock it in between 95 // or another thread/process might be able to lock and unlock it in between
93 // each call. 96 // each call.
94 bool Purge(Time current_time); 97 bool Purge(Time current_time);
95 98
96 // Purge and release as much memory as possible to the OS. 99 // Release as much memory as possible to the OS. The change in size will
97 // Note: The amount of memory that can be released to the OS is platform 100 // be reflected by the return value of mapped_size().
98 // specific. Best case, all but one page is released. Worst case, nothing 101 // Note: It is an error to call this if IsShrinkingSupported() returns false.
99 // is released. 102 void Shrink();
100 bool PurgeAndTruncate(Time current_time);
101 103
102 // Returns true if memory is still resident. 104 // Returns true if memory is still resident.
103 bool IsMemoryResident() const; 105 bool IsMemoryResident() const;
104 106
105 // Closes the open discardable memory segment. 107 // Closes the open discardable memory segment.
106 // It is safe to call Close repeatedly. 108 // It is safe to call Close repeatedly.
107 void Close(); 109 void Close();
108 110
109 // Shares the discardable memory segment to another process. Attempts to 111 // Shares the discardable memory segment to another process. Attempts to
110 // create a platform-specific |new_handle| which can be used in a remote 112 // create a platform-specific |new_handle| which can be used in a remote
(...skipping 19 matching lines...) Expand all
130 // synchronized somehow. Use a collision warner to detect incorrect usage. 132 // synchronized somehow. Use a collision warner to detect incorrect usage.
131 DFAKE_MUTEX(thread_collision_warner_); 133 DFAKE_MUTEX(thread_collision_warner_);
132 Time last_known_usage_; 134 Time last_known_usage_;
133 135
134 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); 136 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory);
135 }; 137 };
136 138
137 } // namespace base 139 } // namespace base
138 140
139 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ 141 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/discardable_shared_memory.cc » ('j') | base/memory/discardable_shared_memory_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698