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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Address on danakj@'s review Created 3 years, 10 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/shared_memory_posix.cc
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index 3a18faa83dd70e82c8381d33cc247afa270339a9..f0018c333fff52ccfcc63dac4764e7e64b1e976d 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -15,6 +15,7 @@
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/shared_memory_helper.h"
+#include "base/memory/shared_memory_tracker.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/safe_strerror.h"
#include "base/process/process_metrics.h"
@@ -283,8 +284,10 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) {
bool mmap_succeeded = memory_ != (void*)-1 && memory_ != NULL;
if (mmap_succeeded) {
mapped_size_ = bytes;
- DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
- (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
+ DCHECK_EQ(0U,
+ reinterpret_cast<uintptr_t>(memory_) &
+ (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
+ SharedMemoryTracker::GetInstance()->IncrementMemoryUsage(*this);
} else {
memory_ = NULL;
}
@@ -297,6 +300,7 @@ bool SharedMemory::Unmap() {
return false;
munmap(memory_, mapped_size_);
+ SharedMemoryTracker::GetInstance()->DecrementMemoryUsage(*this);
memory_ = NULL;
mapped_size_ = 0;
return true;
@@ -390,4 +394,14 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
return true;
}
+bool SharedMemory::GetUniqueId(SharedMemory::UniqueId* id) const {
+ base::ThreadRestrictions::AssertIOAllowed();
+ struct stat file_stat;
+ if (fstat(static_cast<int>(handle().fd), &file_stat) != 0)
Primiano Tucci (use gerrit) 2017/02/27 14:10:50 as this is a I/O syscall it might be safer to wrap
hajimehoshi 2017/02/28 06:59:25 Done (Darwin doesn't reach here anyway).
+ return false;
+ id->first = file_stat.st_dev;
+ id->second = file_stat.st_ino;
+ return true;
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698