summaryrefslogtreecommitdiffstats
path: root/gpu
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 01:23:21 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 01:23:21 +0000
commitbededbcd758985de83d69133035008a0bdd83484 (patch)
tree45f4927144b2cc3657292bf232ffa12b5a8618a1 /gpu
parent5d6f6371796a96d51cea7abdb3878e1c8bb92fc5 (diff)
downloadchromium_src-bededbcd758985de83d69133035008a0bdd83484.zip
chromium_src-bededbcd758985de83d69133035008a0bdd83484.tar.gz
chromium_src-bededbcd758985de83d69133035008a0bdd83484.tar.bz2
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
Diffstat (limited to 'gpu')
-rw-r--r--gpu/common/gpu_trace_event.cc34
-rw-r--r--gpu/common/gpu_trace_event.h9
2 files changed, 27 insertions, 16 deletions
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<base::subtle::Atomic32>(enabled));
+ static_cast<base::subtle::Atomic32>(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<int>(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<base::subtle::Atomic32>(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<base::subtle::Atomic32>(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<base::subtle::Atomic32>(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<TraceCategory> categories_;
scoped_ptr<OutputCallback> output_callback_;
scoped_ptr<BufferFullCallback> buffer_full_callback_;
std::vector<TraceEvent> logged_events_;