Index: base/memory/discardable_memory_allocator_android.h |
diff --git a/base/memory/discardable_memory_allocator_android.h b/base/memory/discardable_memory_allocator_android.h |
index eea57fb3893a827c40063dcafb520650ed010d8b..42f52a69ec259fbfe5dca5032cbdbfe96263ce83 100644 |
--- a/base/memory/discardable_memory_allocator_android.h |
+++ b/base/memory/discardable_memory_allocator_android.h |
@@ -11,14 +11,49 @@ |
#include "base/basictypes.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/scoped_vector.h" |
-#include "base/synchronization/lock.h" |
-#include "base/threading/thread_checker.h" |
namespace base { |
+namespace internal { |
-class DiscardableMemory; |
+// WARNING: The classes below are *NOT* thread-safe! This means that it's the |
+// responsibility of the client (e.g. DiscardableMemoryAshmem) to synchronize |
+// operations on a same allocator instance. |
-namespace internal { |
+class AshmemRegion; |
+ |
+// Internal class, whose instances are returned to the client of the allocator |
+// (e.g. DiscardableMemoryAshmem), that mimicks the DiscardableMemory interface. |
+class DiscardableAshmemChunk { |
+ public: |
+ // WARNING: This notifies the allocator instance from which this instance was |
+ // constructed, i.e. see the thread-safety warning above. |
+ ~DiscardableAshmemChunk(); |
+ |
+ // Returns whether the memory is still resident. |
+ bool Lock(); |
+ |
+ void Unlock(); |
+ |
+ void* Memory() const; |
+ |
+ private: |
+ friend class AshmemRegion; |
+ |
+ DiscardableAshmemChunk(AshmemRegion* ashmem_region, |
+ int fd, |
+ void* address, |
+ size_t offset, |
+ size_t size); |
+ |
+ AshmemRegion* const ashmem_region_; |
+ const int fd_; |
+ void* const address_; |
+ const size_t offset_; |
+ const size_t size_; |
+ bool locked_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DiscardableAshmemChunk); |
+}; |
// On Android ashmem is used to implement discardable memory. It is backed by a |
reveman
2014/04/26 00:13:37
nit: Please remove "Android" from here if this cod
Philippe
2014/04/28 12:23:14
Done.
|
// file (descriptor) thus is a limited resource. This allocator minimizes the |
@@ -26,10 +61,6 @@ namespace internal { |
// chunks to the client. |
// Allocated chunks are systematically aligned on a page boundary therefore this |
// allocator should not be used for small allocations. |
-// |
-// Threading: The allocator must be deleted on the thread it was constructed on |
-// although its Allocate() method can be invoked on any thread. See |
-// discardable_memory.h for DiscardableMemory's threading guarantees. |
class BASE_EXPORT_PRIVATE DiscardableMemoryAllocator { |
reveman
2014/04/26 00:13:37
What's the correct name for this class and these f
Philippe
2014/04/28 12:23:14
I had suggested in my previous comment to keep the
reveman
2014/04/28 15:39:16
Sorry I missed that. I think it makes sense as par
Philippe
2014/04/28 15:53:45
No problem, I was worried about increasing the dif
|
public: |
// Note that |name| is only used for debugging/measurement purposes. |
@@ -40,24 +71,21 @@ class BASE_EXPORT_PRIVATE DiscardableMemoryAllocator { |
~DiscardableMemoryAllocator(); |
- // Note that the allocator must outlive the returned DiscardableMemory |
+ // Note that the allocator must outlive the returned DiscardableAshmemChunk |
// instance. |
- scoped_ptr<DiscardableMemory> Allocate(size_t size); |
+ scoped_ptr<DiscardableAshmemChunk> Allocate(size_t size); |
// Returns the size of the last ashmem region which was created. This is used |
// for testing only. |
size_t last_ashmem_region_size() const; |
private: |
- class AshmemRegion; |
- class DiscardableAshmemChunk; |
+ friend class AshmemRegion; |
- void DeleteAshmemRegion_Locked(AshmemRegion* region); |
+ void DeleteAshmemRegion(AshmemRegion* region); |
- ThreadChecker thread_checker_; |
const std::string name_; |
const size_t ashmem_region_size_; |
- mutable Lock lock_; |
size_t last_ashmem_region_size_; |
ScopedVector<AshmemRegion> ashmem_regions_; |