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

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

Issue 809603004: base: Add ashmem support to base::DiscardableSharedMemory implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing GetPageSize on iOS Created 6 years 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 #ifndef NDEBUG
9 #include <set>
10 #endif
11
8 #include "base/base_export.h" 12 #include "base/base_export.h"
9 #include "base/memory/shared_memory.h" 13 #include "base/memory/shared_memory.h"
10 #include "base/time/time.h" 14 #include "base/time/time.h"
11 15
12 namespace base { 16 namespace base {
13 17
14 // Platform abstraction for discardable shared memory. 18 // Platform abstraction for discardable shared memory.
15 class BASE_EXPORT DiscardableSharedMemory { 19 class BASE_EXPORT DiscardableSharedMemory {
16 public: 20 public:
17 DiscardableSharedMemory(); 21 DiscardableSharedMemory();
18 22
19 // Create a new DiscardableSharedMemory object from an existing, open shared 23 // Create a new DiscardableSharedMemory object from an existing, open shared
20 // memory file. 24 // memory file.
21 explicit DiscardableSharedMemory(SharedMemoryHandle handle); 25 explicit DiscardableSharedMemory(SharedMemoryHandle handle);
22 26
23 // Closes any open files. 27 // Closes any open files.
24 virtual ~DiscardableSharedMemory(); 28 virtual ~DiscardableSharedMemory();
25 29
26 // Creates and maps a locked DiscardableSharedMemory object with |size|. 30 // Creates and maps a locked DiscardableSharedMemory object with |size|.
27 // Returns true on success and false on failure. 31 // Returns true on success and false on failure.
28 bool CreateAndMap(size_t size); 32 bool CreateAndMap(size_t size);
29 33
30 // Maps the discardable memory into the caller's address space. 34 // Maps the discardable memory into the caller's address space.
31 // Returns true on success, false otherwise. 35 // Returns true on success, false otherwise.
32 bool Map(size_t size); 36 bool Map(size_t size);
33 37
34 // The actual size of the mapped memory (may be larger than requested). 38 // The actual size of the mapped memory (may be larger than requested).
35 size_t mapped_size() const { return shared_memory_.mapped_size(); } 39 size_t mapped_size() const { return mapped_size_; }
36 40
37 // Returns a shared memory handle for this DiscardableSharedMemory object. 41 // Returns a shared memory handle for this DiscardableSharedMemory object.
38 SharedMemoryHandle handle() const { return shared_memory_.handle(); } 42 SharedMemoryHandle handle() const { return shared_memory_.handle(); }
39 43
40 // Locks the memory so that it will not be purged by the system. Returns 44 // Locks a range of memory so that it will not be purged by the system.
41 // true if successful and the memory is still resident. Locking can fail 45 // Returns true if successful and the memory is still resident. Locking can
42 // for three reasons; object might have been purged, our last known usage 46 // fail for three reasons; object might have been purged, our last known usage
43 // timestamp might be out of date or memory might already be locked. Last 47 // timestamp might be out of date or memory might already be locked. Last
44 // know usage time is updated to the actual last usage timestamp if memory 48 // know usage time is updated to the actual last usage timestamp if memory
45 // is still resident or 0 if not. 49 // is still resident or 0 if not. The range of memory must be unlocked. The
46 bool Lock(); 50 // result of trying to lock an already locked range is undefined.
51 bool Lock(size_t offset, size_t length);
47 52
48 // Unlock previously successfully locked memory. 53 // Unlock a previously successfully locked range of memory. The range of
49 void Unlock(); 54 // memory must be locked. The result of trying to unlock a not
55 // previously locked range is undefined.
56 void Unlock(size_t offset, size_t length);
50 57
51 // Gets a pointer to the opened discardable memory space. Discardable memory 58 // Gets a pointer to the opened discardable memory space. Discardable memory
52 // must have been mapped via Map(). 59 // must have been mapped via Map().
53 void* memory() const; 60 void* memory() const;
54 61
55 // Returns the last know usage time for DiscardableSharedMemory object. This 62 // Returns the last know usage time for DiscardableSharedMemory object. This
56 // may be earlier than the "true" usage time when memory has been used by a 63 // may be earlier than the "true" usage time when memory has been used by a
57 // different process. Returns NULL time if purged. 64 // different process. Returns NULL time if purged.
58 Time last_known_usage() const { return last_known_usage_; } 65 Time last_known_usage() const { return last_known_usage_; }
59 66
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 bool ShareToProcess(ProcessHandle process_handle, 99 bool ShareToProcess(ProcessHandle process_handle,
93 SharedMemoryHandle* new_handle) { 100 SharedMemoryHandle* new_handle) {
94 return shared_memory_.ShareToProcess(process_handle, new_handle); 101 return shared_memory_.ShareToProcess(process_handle, new_handle);
95 } 102 }
96 103
97 private: 104 private:
98 // Virtual for tests. 105 // Virtual for tests.
99 virtual Time Now() const; 106 virtual Time Now() const;
100 107
101 SharedMemory shared_memory_; 108 SharedMemory shared_memory_;
109 size_t mapped_size_;
110 size_t locked_page_count_;
111 #ifndef NDEBUG
112 std::set<size_t> locked_pages_;
113 #endif
102 Time last_known_usage_; 114 Time last_known_usage_;
103 115
104 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory); 116 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemory);
105 }; 117 };
106 118
107 } // namespace base 119 } // namespace base
108 120
109 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_ 121 #endif // BASE_MEMORY_DISCARDABLE_SHARED_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698