OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_MEMORY_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 // memory, use it as quickly as possible, and then unlock it. | 37 // memory, use it as quickly as possible, and then unlock it. |
38 // - Because of memory alignment, the amount of memory allocated can be | 38 // - Because of memory alignment, the amount of memory allocated can be |
39 // larger than the requested memory size. It is not very efficient for | 39 // larger than the requested memory size. It is not very efficient for |
40 // small allocations. | 40 // small allocations. |
41 // | 41 // |
42 // References: | 42 // References: |
43 // - Linux: http://lwn.net/Articles/452035/ | 43 // - Linux: http://lwn.net/Articles/452035/ |
44 // - Mac: http://trac.webkit.org/browser/trunk/Source/WebCore/platform/mac/Pur geableBufferMac.cpp | 44 // - Mac: http://trac.webkit.org/browser/trunk/Source/WebCore/platform/mac/Pur geableBufferMac.cpp |
45 // the comment starting with "vm_object_purgable_control" at | 45 // the comment starting with "vm_object_purgable_control" at |
46 // http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/v m_object.c | 46 // http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/v m_object.c |
47 // | |
48 // Thread-safety: DiscardableMemory instances are not thread-safe. | |
pasko
2013/10/25 15:21:13
nit: It should probably also say somewhere that it
Philippe
2013/10/28 09:44:43
Good point although David wants to move to a point
reveman
2013/10/28 15:45:23
If the platform specific DM implementation require
Philippe
2013/10/28 15:49:14
+1 to that.
| |
47 class BASE_EXPORT DiscardableMemory { | 49 class BASE_EXPORT DiscardableMemory { |
48 public: | 50 public: |
49 virtual ~DiscardableMemory() {} | 51 virtual ~DiscardableMemory() {} |
50 | 52 |
51 // Returns whether the system supports discardable memory. | 53 // Returns whether the system supports discardable memory. |
52 static bool Supported(); | 54 static bool Supported(); |
53 | 55 |
54 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); | 56 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); |
55 | 57 |
58 // Returns the memory's actual size that is greater or equal than the | |
59 // size requested at construction. | |
60 virtual size_t Size() const = 0; | |
61 | |
56 // Locks the memory so that it will not be purged by the system. Returns | 62 // Locks the memory so that it will not be purged by the system. Returns |
57 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is | 63 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is |
58 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and | 64 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and |
59 // a new one should be created. If the return value is | 65 // a new one should be created. If the return value is |
60 // DISCARDABLE_MEMORY_PURGED then the memory is present but any data that | 66 // DISCARDABLE_MEMORY_PURGED then the memory is present but any data that |
61 // was in it is gone. | 67 // was in it is gone. |
62 virtual LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT = 0; | 68 virtual LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT = 0; |
63 | 69 |
64 // Unlocks the memory so that it can be purged by the system. Must be called | 70 // Unlocks the memory so that it can be purged by the system. Must be called |
65 // after every successful lock call. | 71 // after every successful lock call. |
(...skipping 10 matching lines...) Expand all Loading... | |
76 static bool PurgeForTestingSupported(); | 82 static bool PurgeForTestingSupported(); |
77 | 83 |
78 // Purge all discardable memory in the system. This call has global effects | 84 // Purge all discardable memory in the system. This call has global effects |
79 // across all running processes, so it should only be used for testing! | 85 // across all running processes, so it should only be used for testing! |
80 static void PurgeForTesting(); | 86 static void PurgeForTesting(); |
81 }; | 87 }; |
82 | 88 |
83 } // namespace base | 89 } // namespace base |
84 | 90 |
85 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 91 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |