From bededbcd758985de83d69133035008a0bdd83484 Mon Sep 17 00:00:00 2001 From: "jbates@chromium.org" Date: Tue, 26 Apr 2011 01:23:21 +0000 Subject: gpu_trace_event static category pointers are no longer dangling at shutdown. BUG=80184 TEST=tbd Review URL: http://codereview.chromium.org/6883150 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82963 0039d316-1c4b-4281-b951-d872f2087c98 --- gpu/common/gpu_trace_event.cc | 34 ++++++++++++++++++++-------------- gpu/common/gpu_trace_event.h | 9 +++++++-- 2 files changed, 27 insertions(+), 16 deletions(-) (limited to 'gpu') diff --git a/gpu/common/gpu_trace_event.cc b/gpu/common/gpu_trace_event.cc index 241ca4e..b92ce6d 100644 --- a/gpu/common/gpu_trace_event.cc +++ b/gpu/common/gpu_trace_event.cc @@ -21,15 +21,20 @@ namespace gpu { #define TRACE_EVENT_BUFFER_SIZE 500000 #define TRACE_EVENT_BATCH_SIZE 1000 +#define TRACE_EVENT_MAX_CATEGORIES 42 + +static TraceCategory g_categories[TRACE_EVENT_MAX_CATEGORIES]; +static int g_category_index = 0; + //////////////////////////////////////////////////////////////////////////////// // // TraceLog::Category // //////////////////////////////////////////////////////////////////////////////// -TraceCategory::TraceCategory(const char* name, bool enabled) - : name_(name) { +TraceCategory::TraceCategory() + : name_(NULL) { base::subtle::NoBarrier_Store(&enabled_, - static_cast(enabled)); + static_cast(0)); } TraceCategory::~TraceCategory() { @@ -215,14 +220,15 @@ TraceLog::~TraceLog() { TraceCategory* TraceLog::GetCategory(const char* name) { AutoLock lock(lock_); - // TODO(nduca): replace with a hash_map. - for (int i = static_cast(categories_.size()) - 1; i >= 0; i--) { - if (strcmp(categories_[i]->name(), name) == 0) - return categories_[i]; + for (int i = 0; i < g_category_index; i++) { + if (strcmp(g_categories[i].name(), name) == 0) + return &g_categories[i]; } - TraceCategory* category = new TraceCategory(name, enabled_); - categories_.push_back(category); - return category; + CHECK(g_category_index < TRACE_EVENT_MAX_CATEGORIES) << + "must increase TRACE_EVENT_MAX_CATEGORIES"; + int new_index = g_category_index++; + g_categories[new_index].set(name, enabled_); + return &g_categories[new_index]; } void TraceLog::SetEnabled(bool enabled) { @@ -232,14 +238,14 @@ void TraceLog::SetEnabled(bool enabled) { if (enabled) { // Enable all categories. enabled_ = true; - for (size_t i = 0; i < categories_.size(); i++) { - base::subtle::NoBarrier_Store(&categories_[i]->enabled_, + for (int i = 0; i < g_category_index; i++) { + base::subtle::NoBarrier_Store(&g_categories[i].enabled_, static_cast(1)); } } else { // Disable all categories. - for (size_t i = 0; i < categories_.size(); i++) { - base::subtle::NoBarrier_Store(&categories_[i]->enabled_, + for (int i = 0; i < g_category_index; i++) { + base::subtle::NoBarrier_Store(&g_categories[i].enabled_, static_cast(0)); } enabled_ = false; diff --git a/gpu/common/gpu_trace_event.h b/gpu/common/gpu_trace_event.h index d71e059..581b66e 100644 --- a/gpu/common/gpu_trace_event.h +++ b/gpu/common/gpu_trace_event.h @@ -181,9 +181,15 @@ namespace gpu { // to threading issues. Use the TraceLog methods instead. class TraceCategory { public: - TraceCategory(const char* name, bool enabled); + TraceCategory(); ~TraceCategory(); + void set(const char* name, bool enabled) { + name_ = name; + base::subtle::NoBarrier_Store(&enabled_, + static_cast(enabled)); + } + const char* name() const { return name_; } // NEVER read these directly, let the macros do it for you @@ -389,7 +395,6 @@ class TraceLog { // synchronization. base::Lock lock_; bool enabled_; - ScopedVector categories_; scoped_ptr output_callback_; scoped_ptr buffer_full_callback_; std::vector logged_events_; -- cgit v1.1