Index: src/zone/accounting-allocator.h |
diff --git a/src/zone/accounting-allocator.h b/src/zone/accounting-allocator.h |
index 01c38186d6809e44a4f08ebcc287ee1d09dcdc5d..726808192f1e0ea7d10235faccc9166fc699049d 100644 |
--- a/src/zone/accounting-allocator.h |
+++ b/src/zone/accounting-allocator.h |
@@ -19,19 +19,58 @@ namespace internal { |
class AccountingAllocator { |
public: |
- AccountingAllocator() = default; |
- virtual ~AccountingAllocator() = default; |
+ AccountingAllocator(); |
+ virtual ~AccountingAllocator(); |
- virtual Segment* AllocateSegment(size_t bytes); |
- virtual void FreeSegment(Segment* memory); |
+ // Gets an empty segment from pool or creates a new one. |
+ virtual Segment* GetSegment(size_t bytes); |
+ // Return non needed segments here to insert them into the pool |
+ // or release them in case the pool is full. Operation may or may |
+ // not be asynchronous, depending on memory pressure. |
+ virtual void ReturnSegment(Segment* memory); |
size_t GetCurrentMemoryUsage() const; |
size_t GetMaxMemoryUsage() const; |
+ size_t GetCurrentPoolSize() const; |
+ |
+ void MemoryPressureNotification(MemoryPressureLevel level); |
+ |
private: |
+ static const uint8_t kMinSegmentSizePower = 13; |
+ static const uint8_t kMaxSegmentSizePower = 18; |
+ static const uint8_t kMaxSegmentsPerBucket = 5; |
+ |
+ STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); |
+ |
+ // Allocated a new segment. Returns nullptr on failed allocation. |
+ Segment* AllocateSegment(size_t bytes); |
+ // Frees a non needed segment. Blocks the current thread. |
+ void FreeSegment(Segment* memory); |
+ |
+ // Returns a segment from the pool of at least the requested size. |
+ Segment* GetSegmentFromPool(size_t requested_size); |
+ // Trys to add a segment to the pool. Returns false if the pool is full. |
+ bool AddSegmentToPool(Segment* segment); |
+ |
+ // Empties the pool and puts all its contents onto the garbage stack. |
+ void ClearPool(); |
+ |
+ Segment** unused_segments_heads_ = |
Toon Verwaest
2016/09/21 11:18:07
Segment* unused_segments_heads_[1+kMax-kMin], same
heimbuef
2016/09/21 11:39:23
Format checker does not like no spaces in between
|
+ new Segment*[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
+ |
+ size_t* unused_segments_sizes = |
+ new size_t[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
+ |
+ size_t unused_segments_size_ = 0; |
+ |
+ base::Mutex* unused_segments_mutex_ = new base::Mutex(); |
+ |
base::AtomicWord current_memory_usage_ = 0; |
base::AtomicWord max_memory_usage_ = 0; |
+ base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; |
+ |
DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); |
}; |