| Index: src/platform.h
|
| diff --git a/src/platform.h b/src/platform.h
|
| index d95ee62b1275274b9cde422de42b01fc103fdaa5..85901240f3d0740e86d1f6569710906e8754da1c 100644
|
| --- a/src/platform.h
|
| +++ b/src/platform.h
|
| @@ -301,23 +301,46 @@ class OS {
|
| DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
|
| };
|
|
|
| -
|
| +// Represents and controls an area of reserved memory.
|
| +// Control of the reserved memory can be assigned to another VirtualMemory
|
| +// object by assignment or copy-contructing. This removes the reserved memory
|
| +// from the original object.
|
| class VirtualMemory {
|
| public:
|
| + // Empty VirtualMemory object, controlling no reserved memory.
|
| + VirtualMemory();
|
| +
|
| // Reserves virtual memory with size.
|
| explicit VirtualMemory(size_t size);
|
| +
|
| + // Reserves virtual memory containing an area of the given size that
|
| + // is aligned per alignment. This may not be at the position returned
|
| + // by address().
|
| + VirtualMemory(size_t size, size_t alignment);
|
| +
|
| + // Releases the reserved memory, if any, controlled by this VirtualMemory
|
| + // object.
|
| ~VirtualMemory();
|
|
|
| // Returns whether the memory has been reserved.
|
| bool IsReserved();
|
|
|
| + // Initialize or resets an embedded VirtualMemory object.
|
| + void Reset();
|
| +
|
| // Returns the start address of the reserved memory.
|
| + // If the memory was reserved with an alignment, this address is not
|
| + // necessarily aligned. The user might need to round it up to a multiple of
|
| + // the alignment to get the start of the aligned block.
|
| void* address() {
|
| ASSERT(IsReserved());
|
| return address_;
|
| }
|
|
|
| - // Returns the size of the reserved memory.
|
| + // Returns the size of the reserved memory. The returned value is only
|
| + // meaningful when IsReserved() returns true.
|
| + // If the memory was reserved with an alignment, this size may be larger
|
| + // than the requested size.
|
| size_t size() { return size_; }
|
|
|
| // Commits real memory. Returns whether the operation succeeded.
|
| @@ -326,12 +349,33 @@ class VirtualMemory {
|
| // Uncommit real memory. Returns whether the operation succeeded.
|
| bool Uncommit(void* address, size_t size);
|
|
|
| + void Release() {
|
| + ASSERT(IsReserved());
|
| + // Notice: Order is somportant here. The VirtualMemory object might live
|
| + // inside the allocated region.
|
| + void* address = address_;
|
| + size_t size = size_;
|
| + Reset();
|
| + ReleaseRegion(address, size);
|
| + }
|
| +
|
| + // Assign control of the reserved region to a different VirtualMemory object.
|
| + // The old object is no longer functional (IsReserved() returns false).
|
| + void TakeControl(VirtualMemory* from) {
|
| + ASSERT(!IsReserved());
|
| + address_ = from->address_;
|
| + size_ = from->size_;
|
| + from->Reset();
|
| + }
|
| +
|
| static void* ReserveRegion(size_t size);
|
|
|
| static bool CommitRegion(void* base, size_t size, bool is_executable);
|
|
|
| static bool UncommitRegion(void* base, size_t size);
|
|
|
| + // Must be called with a base pointer that has been returned by ReserveRegion
|
| + // and the same size it was reserved with.
|
| static bool ReleaseRegion(void* base, size_t size);
|
|
|
| private:
|
| @@ -339,6 +383,7 @@ class VirtualMemory {
|
| size_t size_; // Size of the virtual memory.
|
| };
|
|
|
| +
|
| // ----------------------------------------------------------------------------
|
| // Thread
|
| //
|
|
|