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

Side by Side Diff: base/metrics/stats_table.cc

Issue 15403002: Remving global statics from the headers, so we can split-link. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding export Created 7 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/metrics/stats_table.h ('k') | content/common/child_process.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/stats_table.h" 5 #include "base/metrics/stats_table.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // thread exits and return the table slot. 241 // thread exits and return the table slot.
242 // 242 //
243 // Each thread that calls RegisterThread in the StatsTable will have 243 // Each thread that calls RegisterThread in the StatsTable will have
244 // a TLSData stored in its TLS. 244 // a TLSData stored in its TLS.
245 struct StatsTable::TLSData { 245 struct StatsTable::TLSData {
246 StatsTable* table; 246 StatsTable* table;
247 int slot; 247 int slot;
248 }; 248 };
249 249
250 // We keep a singleton table which can be easily accessed. 250 // We keep a singleton table which can be easily accessed.
251 StatsTable* StatsTable::global_table_ = NULL; 251 StatsTable* global_table = NULL;
252 252
253 StatsTable::StatsTable(const std::string& name, int max_threads, 253 StatsTable::StatsTable(const std::string& name, int max_threads,
254 int max_counters) 254 int max_counters)
255 : impl_(NULL), 255 : impl_(NULL),
256 tls_index_(SlotReturnFunction) { 256 tls_index_(SlotReturnFunction) {
257 int table_size = 257 int table_size =
258 AlignedSize(sizeof(Private::TableHeader)) + 258 AlignedSize(sizeof(Private::TableHeader)) +
259 AlignedSize((max_counters * sizeof(char) * kMaxCounterNameLength)) + 259 AlignedSize((max_counters * sizeof(char) * kMaxCounterNameLength)) +
260 AlignedSize((max_threads * sizeof(char) * kMaxThreadNameLength)) + 260 AlignedSize((max_threads * sizeof(char) * kMaxThreadNameLength)) +
261 AlignedSize(max_threads * sizeof(int)) + 261 AlignedSize(max_threads * sizeof(int)) +
(...skipping 12 matching lines...) Expand all
274 UnregisterThread(); 274 UnregisterThread();
275 275
276 // Return ThreadLocalStorage. At this point, if any registered threads 276 // Return ThreadLocalStorage. At this point, if any registered threads
277 // still exist, they cannot Unregister. 277 // still exist, they cannot Unregister.
278 tls_index_.Free(); 278 tls_index_.Free();
279 279
280 // Cleanup our shared memory. 280 // Cleanup our shared memory.
281 delete impl_; 281 delete impl_;
282 282
283 // If we are the global table, unregister ourselves. 283 // If we are the global table, unregister ourselves.
284 if (global_table_ == this) 284 if (global_table == this)
285 global_table_ = NULL; 285 global_table = NULL;
286 }
287
288 StatsTable* StatsTable::current() {
289 return global_table;
290 }
291
292 void StatsTable::set_current(StatsTable* value) {
293 global_table = value;
286 } 294 }
287 295
288 int StatsTable::GetSlot() const { 296 int StatsTable::GetSlot() const {
289 TLSData* data = GetTLSData(); 297 TLSData* data = GetTLSData();
290 if (!data) 298 if (!data)
291 return 0; 299 return 0;
292 return data->slot; 300 return data->slot;
293 } 301 }
294 302
295 int StatsTable::RegisterThread(const std::string& name) { 303 int StatsTable::RegisterThread(const std::string& name) {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 static_cast<TLSData*>(tls_index_.Get()); 559 static_cast<TLSData*>(tls_index_.Get());
552 if (!data) 560 if (!data)
553 return NULL; 561 return NULL;
554 562
555 DCHECK(data->slot); 563 DCHECK(data->slot);
556 DCHECK_EQ(data->table, this); 564 DCHECK_EQ(data->table, this);
557 return data; 565 return data;
558 } 566 }
559 567
560 } // namespace base 568 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/stats_table.h ('k') | content/common/child_process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698