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

Unified Diff: base/metrics/stats_table.cc

Issue 22911027: Pass StatsTable shared memory via global descriptors on Posix rather than using named shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Jar's comments. Created 7 years, 4 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
« no previous file with comments | « base/metrics/stats_table.h ('k') | content/browser/child_process_launcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/stats_table.cc
diff --git a/base/metrics/stats_table.cc b/base/metrics/stats_table.cc
index 4a3d939cfe093c460025ff2ed26c699fbc8fdd7b..e0011a9f979051b64de17116714d54b42ae3dec9 100644
--- a/base/metrics/stats_table.cc
+++ b/base/metrics/stats_table.cc
@@ -15,7 +15,9 @@
#include "base/threading/thread_local_storage.h"
#if defined(OS_POSIX)
+#include "base/posix/global_descriptors.h"
#include "errno.h"
+#include "ipc/ipc_descriptors.h"
#endif
namespace base {
@@ -106,7 +108,7 @@ class StatsTable::Private {
static Private* New(const std::string& name, int size,
int max_threads, int max_counters);
jar (doing other things) 2013/08/22 00:29:38 nit: fix indentation. Chromium standard for decla
rmcilroy 2013/08/22 10:03:55 Done.
- SharedMemory* shared_memory() { return &shared_memory_; }
+ SharedMemory* shared_memory() { return shared_memory_.get(); }
// Accessors for our header pointers
TableHeader* table_header() const { return table_header_; }
@@ -136,8 +138,9 @@ class StatsTable::Private {
private:
// Constructor is private because you should use New() instead.
- Private()
- : table_header_(NULL),
+ explicit Private(SharedMemory* shared_memory)
+ : shared_memory_(shared_memory),
+ table_header_(NULL),
thread_names_table_(NULL),
thread_tid_table_(NULL),
thread_pid_table_(NULL),
@@ -145,6 +148,9 @@ class StatsTable::Private {
data_table_(NULL) {
}
+ // Create or open the SharedMemory used by the stats table.
+ static SharedMemory* CreateSharedMemory(int size);
+
// Initializes the table on first access. Sets header values
// appropriately and zeroes all counters.
void InitializeTable(void* memory, int size, int max_counters,
@@ -153,7 +159,7 @@ class StatsTable::Private {
// Initializes our in-memory pointers into a pre-created StatsTable.
void ComputeMappedPointers(void* memory);
- SharedMemory shared_memory_;
+ scoped_ptr<SharedMemory> shared_memory_;
TableHeader* table_header_;
char* thread_names_table_;
PlatformThreadId* thread_tid_table_;
@@ -167,13 +173,14 @@ StatsTable::Private* StatsTable::Private::New(const std::string& name,
int size,
int max_threads,
int max_counters) {
- scoped_ptr<Private> priv(new Private());
- if (!priv->shared_memory_.CreateNamed(name, true, size))
+ scoped_ptr<SharedMemory> shared_memory(CreateSharedMemory(size));
+ if (!shared_memory.get())
return NULL;
- if (!priv->shared_memory_.Map(size))
+ if (!shared_memory->Map(size))
return NULL;
- void* memory = priv->shared_memory_.memory();
+ void* memory = shared_memory->memory();
+ scoped_ptr<Private> priv(new Private(shared_memory.release()));
jar (doing other things) 2013/08/22 00:29:38 nit: Style: Don't abbreviate in names. Sadly, the
rmcilroy 2013/08/22 10:03:55 Done (went with Internal)
TableHeader* header = static_cast<TableHeader*>(memory);
// If the version does not match, then assume the table needs
@@ -187,6 +194,29 @@ StatsTable::Private* StatsTable::Private::New(const std::string& name,
return priv.release();
}
+// static
+SharedMemory* StatsTable::Private::CreateSharedMemory(int size) {
+#if defined(OS_POSIX)
+ GlobalDescriptors* global_descriptors = GlobalDescriptors::GetInstance();
+ if (global_descriptors->MaybeGet(kStatsTableSharedMemFd) != -1) {
+ // Open the shared memory file descriptor passed by the browser process.
+ FileDescriptor file_descriptor(
+ global_descriptors->Get(kStatsTableSharedMemFd), false);
+ return new SharedMemory(file_descriptor, false);
+ }
+ // Otherwise we need to create it.
+ scoped_ptr<SharedMemory> shared_memory(new SharedMemory());
+ if (!shared_memory->CreateAnonymous(size))
+ return NULL;
+ return shared_memory.release();
+#elif defined(OS_WIN)
+ scoped_ptr<SharedMemory> shared_memory(new SharedMemory());
+ if (!shared_memory.CreateNamed(name, true, size))
+ return NULL;
+ return shared_memory.release();
+#endif
+}
+
void StatsTable::Private::InitializeTable(void* memory, int size,
int max_counters,
int max_threads) {
@@ -565,4 +595,10 @@ StatsTable::TLSData* StatsTable::GetTLSData() const {
return data;
}
+#if defined(OS_POSIX)
+SharedMemoryHandle StatsTable::GetSharedMemoryHandle() const {
+ return impl_ ? impl_->shared_memory()->handle() : SharedMemory::NULLHandle();
+}
+#endif
+
} // namespace base
« no previous file with comments | « base/metrics/stats_table.h ('k') | content/browser/child_process_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698