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

Unified Diff: base/memory/shared_memory_posix.cc

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Use 1 bucket / actually no more bucket 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..5d6d0ad572467d8c9ba5b681521486628c961ec9 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"
@@ -284,7 +285,8 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) {
if (mmap_succeeded) {
mapped_size_ = bytes;
DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) &
- (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
+ (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1));
+ SharedMemoryTracker::GetInstance()->IncrementMemoryUsage(*this);
} else {
memory_ = NULL;
}
@@ -297,6 +299,7 @@ bool SharedMemory::Unmap() {
return false;
munmap(memory_, mapped_size_);
+ SharedMemoryTracker::GetInstance()->DecrementMemoryUsage(*this);
memory_ = NULL;
mapped_size_ = 0;
return true;
@@ -390,4 +393,16 @@ bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
return true;
}
+#if !defined(OS_MACOSX) || defined(OS_IOS)
danakj 2017/02/24 15:30:28 If I'm reading BUILD.gn right, this file isn't par
hajimehoshi 2017/02/27 07:51:54 You're right. Done.
+bool SharedMemory::GetUniqueId(SharedMemory::Id* id) const {
+ base::ThreadRestrictions::AssertIOAllowed();
+ struct stat file_stat;
+ if (fstat(static_cast<int>(handle().fd), &file_stat) != 0)
+ return false;
+ id->first = file_stat.st_dev;
+ id->second = file_stat.st_ino;
+ return true;
+}
+#endif // !defined(OS_MACOSX) || defined(OS_IOS)
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698