summaryrefslogtreecommitdiffstats
path: root/base/logging_win.cc
diff options
context:
space:
mode:
authorsiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 15:24:49 +0000
committersiggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 15:24:49 +0000
commit297d0e5e3659a6d4a80906e4fc8e757ababae82d (patch)
tree08b75a511be120bf4b553965d161173e262bde6c /base/logging_win.cc
parentc90e135d0a9097774779813189f4bcea0f16ce91 (diff)
downloadchromium_src-297d0e5e3659a6d4a80906e4fc8e757ababae82d.zip
chromium_src-297d0e5e3659a6d4a80906e4fc8e757ababae82d.tar.gz
chromium_src-297d0e5e3659a6d4a80906e4fc8e757ababae82d.tar.bz2
Add a StaticMemorySingletonTraits class to allow constructing singletons in data segment.
Change logging_win to use same. BUG=none TEST=Unittests in this change. Review URL: http://codereview.chromium.org/2023003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/logging_win.cc')
-rw-r--r--base/logging_win.cc36
1 files changed, 3 insertions, 33 deletions
diff --git a/base/logging_win.cc b/base/logging_win.cc
index d28ce91..2c2d6b0 100644
--- a/base/logging_win.cc
+++ b/base/logging_win.cc
@@ -9,39 +9,9 @@
namespace {
-struct LogEventProviderTraits {
- // WARNING: User has to deal with get() returning NULL.
- static logging::LogEventProvider* New() {
- if (base::subtle::NoBarrier_AtomicExchange(&dead_, 1))
- return NULL;
- logging::LogEventProvider* ptr =
- reinterpret_cast<logging::LogEventProvider*>(buffer_);
- // We are protected by a memory barrier.
- new(ptr) logging::LogEventProvider();
- return ptr;
- }
-
- static void Delete(logging::LogEventProvider* p) {
- base::subtle::NoBarrier_Store(&dead_, 1);
- MemoryBarrier();
- p->logging::LogEventProvider::~LogEventProvider();
- }
-
- static const bool kRegisterAtExit = true;
-
- private:
- static const size_t kBufferSize = (sizeof(logging::LogEventProvider) +
- sizeof(intptr_t) - 1) / sizeof(intptr_t);
- static intptr_t buffer_[kBufferSize];
-
- // Signal the object was already deleted, so it is not revived.
- static base::subtle::Atomic32 dead_;
-};
-
-intptr_t LogEventProviderTraits::buffer_[kBufferSize];
-base::subtle::Atomic32 LogEventProviderTraits::dead_ = 0;
-
-Singleton<logging::LogEventProvider, LogEventProviderTraits> log_provider;
+typedef StaticMemorySingletonTraits<logging::LogEventProvider>
+ LogEventSingletonTraits;
+Singleton<logging::LogEventProvider, LogEventSingletonTraits> log_provider;
} // namespace