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

Unified Diff: base/memory/discardable_memory.h

Issue 17106004: Add discardable memory emulation for non-android/mac platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing review. Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: base/memory/discardable_memory.h
diff --git a/base/memory/discardable_memory.h b/base/memory/discardable_memory.h
index d6e91b979d5a46fdd50e6ef07ab4f52a904bc042..eb3d42b42cf6a728b851fde17367004f9c557dce 100644
--- a/base/memory/discardable_memory.h
+++ b/base/memory/discardable_memory.h
@@ -8,9 +8,14 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/threading/non_thread_safe.h"
namespace base {
+namespace internal {
+ class DiscardableMemoryProvider;
willchan no longer on Chromium 2013/10/01 18:12:05 No indentation
reveman 2013/10/09 22:40:24 Done.
+}
+
enum LockDiscardableMemoryStatus {
DISCARDABLE_MEMORY_FAILED = -1,
DISCARDABLE_MEMORY_PURGED = 0,
@@ -37,6 +42,9 @@ enum LockDiscardableMemoryStatus {
// - Because of memory alignment, the amount of memory allocated can be
// larger than the requested memory size. It is not very efficient for
// small allocations.
+// - A discardable memory instance is not thread safe. It is the
+// responsibility of users of discardable memory to ensure there is no
+// contention for the instances.
willchan no longer on Chromium 2013/10/01 18:12:05 It's more technically correct to say there are no
reveman 2013/10/09 22:40:24 Done.
//
// References:
// - Linux: http://lwn.net/Articles/452035/
@@ -51,8 +59,9 @@ class BASE_EXPORT DiscardableMemory {
// The opened file will also be closed after this.
~DiscardableMemory();
- // Check whether the system supports discardable memory.
- static bool Supported();
+ // Check whether the system supports discardable memory natively. Returns
+ // false if the support is emulated.
+ static bool SupportedNatively();
// Initialize the DiscardableMemory object. On success, this function returns
// true and the memory is locked. This should only be called once.
@@ -72,6 +81,8 @@ class BASE_EXPORT DiscardableMemory {
// after every successful lock call.
void Unlock();
+ bool is_locked() const { return is_locked_; }
+
// Return the memory address held by this object. The object must be locked
// before calling this. Otherwise, this will cause a DCHECK error.
void* Memory() const;
@@ -87,6 +98,16 @@ class BASE_EXPORT DiscardableMemory {
static void PurgeForTesting();
private:
+#if !defined(DISCARDABLE_MEMORY_ALWAYS_SUPPORTED_NATIVELY)
+ friend class base::internal::DiscardableMemoryProvider;
willchan no longer on Chromium 2013/10/01 18:12:05 You can ditch the base::.
reveman 2013/10/09 22:40:24 Done.
+ friend class DiscardableMemoryProviderTest;
+
+ // The following functions are used by the DiscardableMemoryProvider to
+ // allocate and free memory. Allocate returns true if successful.
+ bool Allocate();
+ void Deallocate();
+#endif
+
#if defined(OS_ANDROID)
// Maps the discardable memory into the caller's address space.
// Returns true on success, false otherwise.

Powered by Google App Engine
This is Rietveld 408576698