diff options
author | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 20:47:00 +0000 |
---|---|---|
committer | evanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 20:47:00 +0000 |
commit | d232c09f2584c80b6fde6b987fac32c8de57bfd7 (patch) | |
tree | 9e7601791ee5ccef2bef3bfde9e2eb85a5f095e3 /base/stats_table.cc | |
parent | 76328988113b8bfc1cda9efdc266213199d413ca (diff) | |
download | chromium_src-d232c09f2584c80b6fde6b987fac32c8de57bfd7.zip chromium_src-d232c09f2584c80b6fde6b987fac32c8de57bfd7.tar.gz chromium_src-d232c09f2584c80b6fde6b987fac32c8de57bfd7.tar.bz2 |
Remove use of wide characters in stats table identifiers.
Review URL: http://codereview.chromium.org/11544
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/stats_table.cc')
-rw-r--r-- | base/stats_table.cc | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/base/stats_table.cc b/base/stats_table.cc index 72cc5ab..1f25457 100644 --- a/base/stats_table.cc +++ b/base/stats_table.cc @@ -70,7 +70,7 @@ namespace { const int kTableVersion = 0x13131313; // The name for un-named counters and threads in the table. -const wchar_t kUnknownName[] = L"<unknown>"; +const char kUnknownName[] = "<unknown>"; // Calculates delta to align an offset to the size of an int inline int AlignOffset(int offset) { @@ -109,7 +109,7 @@ class StatsTablePrivate { // Construct a new StatsTablePrivate based on expected size parameters, or // return NULL on failure. - static StatsTablePrivate* New(const std::wstring& name, int size, + static StatsTablePrivate* New(const std::string& name, int size, int max_threads, int max_counters); base::SharedMemory* shared_memory() { return &shared_memory_; } @@ -122,7 +122,7 @@ class StatsTablePrivate { int max_threads() const { return table_header_->max_threads; } // Accessors for our tables - wchar_t* thread_name(int slot_id) const { + char* thread_name(int slot_id) const { return &thread_names_table_[ (slot_id-1) * (StatsTable::kMaxThreadNameLength)]; } @@ -132,7 +132,7 @@ class StatsTablePrivate { int* thread_pid(int slot_id) const { return &(thread_pid_table_[slot_id-1]); } - wchar_t* counter_name(int counter_id) const { + char* counter_name(int counter_id) const { return &counter_names_table_[ (counter_id-1) * (StatsTable::kMaxCounterNameLength)]; } @@ -154,21 +154,21 @@ class StatsTablePrivate { base::SharedMemory shared_memory_; TableHeader* table_header_; - wchar_t* thread_names_table_; + char* thread_names_table_; int* thread_tid_table_; int* thread_pid_table_; - wchar_t* counter_names_table_; + char* counter_names_table_; int* data_table_; }; // static -StatsTablePrivate* StatsTablePrivate::New(const std::wstring& name, +StatsTablePrivate* StatsTablePrivate::New(const std::string& name, int size, int max_threads, int max_counters) { scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate()); - if (!priv->shared_memory_.Create(name, false, true, size)) + if (!priv->shared_memory_.Create(UTF8ToWide(name), false, true, size)) return NULL; if (!priv->shared_memory_.Map(size)) return NULL; @@ -212,8 +212,8 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { // Verify we're looking at a valid StatsTable. DCHECK_EQ(table_header_->version, kTableVersion); - thread_names_table_ = reinterpret_cast<wchar_t*>(data + offset); - offset += sizeof(wchar_t) * + thread_names_table_ = reinterpret_cast<char*>(data + offset); + offset += sizeof(char) * max_threads() * StatsTable::kMaxThreadNameLength; offset += AlignOffset(offset); @@ -225,8 +225,8 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { offset += sizeof(int) * max_threads(); offset += AlignOffset(offset); - counter_names_table_ = reinterpret_cast<wchar_t*>(data + offset); - offset += sizeof(wchar_t) * + counter_names_table_ = reinterpret_cast<char*>(data + offset); + offset += sizeof(char) * max_counters() * StatsTable::kMaxCounterNameLength; offset += AlignOffset(offset); @@ -241,14 +241,14 @@ void StatsTablePrivate::ComputeMappedPointers(void* memory) { // We keep a singleton table which can be easily accessed. StatsTable* StatsTable::global_table_ = NULL; -StatsTable::StatsTable(const std::wstring& name, int max_threads, +StatsTable::StatsTable(const std::string& name, int max_threads, int max_counters) : impl_(NULL), tls_index_(SlotReturnFunction) { int table_size = AlignedSize(sizeof(StatsTablePrivate::TableHeader)) + - AlignedSize((max_counters * sizeof(wchar_t) * kMaxCounterNameLength)) + - AlignedSize((max_threads * sizeof(wchar_t) * kMaxThreadNameLength)) + + AlignedSize((max_counters * sizeof(char) * kMaxCounterNameLength)) + + AlignedSize((max_threads * sizeof(char) * kMaxThreadNameLength)) + AlignedSize(max_threads * sizeof(int)) + AlignedSize(max_threads * sizeof(int)) + AlignedSize((sizeof(int) * (max_counters * max_threads))); @@ -282,7 +282,7 @@ StatsTable::~StatsTable() { global_table_ = NULL; } -int StatsTable::RegisterThread(const std::wstring& name) { +int StatsTable::RegisterThread(const std::string& name) { int slot = 0; // Registering a thread requires that we lock the shared memory @@ -298,10 +298,10 @@ int StatsTable::RegisterThread(const std::wstring& name) { DCHECK(impl_); // We have space, so consume a column in the table. - std::wstring thread_name = name; + std::string thread_name = name; if (name.empty()) thread_name = kUnknownName; - base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(), + base::strlcpy(impl_->thread_name(slot), thread_name.c_str(), kMaxThreadNameLength); *(impl_->thread_tid(slot)) = PlatformThread::CurrentId(); *(impl_->thread_pid(slot)) = base::GetCurrentProcId(); @@ -336,8 +336,8 @@ void StatsTable::UnregisterThread(StatsTableTLSData* data) { DCHECK(impl_); // Mark the slot free by zeroing out the thread name. - wchar_t* name = impl_->thread_name(data->slot); - *name = L'\0'; + char* name = impl_->thread_name(data->slot); + *name = '\0'; // Remove the calling thread's TLS so that it cannot use the slot. tls_index_.Set(NULL); @@ -363,8 +363,8 @@ int StatsTable::CountThreadsRegistered() const { // We intentionally do not lock the table during the operation. int count = 0; for (int index = 1; index <= impl_->max_threads(); index++) { - wchar_t* name = impl_->thread_name(index); - if (*name != L'\0') + char* name = impl_->thread_name(index); + if (*name != '\0') count++; } return count; @@ -391,7 +391,7 @@ int StatsTable::FindEmptyThread() const { int index = 1; for (; index <= impl_->max_threads(); index++) { - wchar_t* name = impl_->thread_name(index); + char* name = impl_->thread_name(index); if (!*name) break; } @@ -400,7 +400,7 @@ int StatsTable::FindEmptyThread() const { return index; } -int StatsTable::FindCounterOrEmptyRow(const std::wstring& name) const { +int StatsTable::FindCounterOrEmptyRow(const std::string& name) const { // Note: the API returns slots numbered from 1..N, although // internally, the array is 0..N-1. This is so that we can return // zero as "not found". @@ -413,16 +413,16 @@ int StatsTable::FindCounterOrEmptyRow(const std::wstring& name) const { int free_slot = 0; for (int index = 1; index <= impl_->max_counters(); index++) { - wchar_t* row_name = impl_->counter_name(index); + char* row_name = impl_->counter_name(index); if (!*row_name && !free_slot) free_slot = index; // save that we found a free slot - else if (!wcsncmp(row_name, name.c_str(), kMaxCounterNameLength)) + else if (!strncmp(row_name, name.c_str(), kMaxCounterNameLength)) return index; } return free_slot; } -int StatsTable::FindCounter(const std::wstring& name) { +int StatsTable::FindCounter(const std::string& name) { // Note: the API returns counters numbered from 1..N, although // internally, the array is 0..N-1. This is so that we can return // zero as "not found". @@ -444,7 +444,7 @@ int StatsTable::FindCounter(const std::wstring& name) { return AddCounter(name); } -int StatsTable::AddCounter(const std::wstring& name) { +int StatsTable::AddCounter(const std::string& name) { DCHECK(impl_); if (!impl_) @@ -461,10 +461,10 @@ int StatsTable::AddCounter(const std::wstring& name) { if (!counter_id) return 0; - std::wstring counter_name = name; + std::string counter_name = name; if (name.empty()) counter_name = kUnknownName; - base::wcslcpy(impl_->counter_name(counter_id), counter_name.c_str(), + base::strlcpy(impl_->counter_name(counter_id), counter_name.c_str(), kMaxCounterNameLength); } @@ -486,7 +486,7 @@ int* StatsTable::GetLocation(int counter_id, int slot_id) const { return &(row[slot_id-1]); } -const wchar_t* StatsTable::GetRowName(int index) const { +const char* StatsTable::GetRowName(int index) const { if (!impl_) return NULL; @@ -510,7 +510,7 @@ int StatsTable::GetRowValue(int index) const { return GetRowValue(index, 0); } -int StatsTable::GetCounterValue(const std::wstring& name, int pid) { +int StatsTable::GetCounterValue(const std::string& name, int pid) { if (!impl_) return 0; @@ -520,7 +520,7 @@ int StatsTable::GetCounterValue(const std::wstring& name, int pid) { return GetRowValue(row, pid); } -int StatsTable::GetCounterValue(const std::wstring& name) { +int StatsTable::GetCounterValue(const std::string& name) { return GetCounterValue(name, 0); } @@ -536,7 +536,7 @@ int StatsTable::GetMaxThreads() const { return impl_->max_threads(); } -int* StatsTable::FindLocation(const wchar_t* name) { +int* StatsTable::FindLocation(const char* name) { // Get the static StatsTable StatsTable *table = StatsTable::current(); if (!table) @@ -545,11 +545,11 @@ int* StatsTable::FindLocation(const wchar_t* name) { // Get the slot for this thread. Try to register // it if none exists. int slot = table->GetSlot(); - if (!slot && !(slot = table->RegisterThread(L""))) + if (!slot && !(slot = table->RegisterThread(""))) return NULL; // Find the counter id for the counter. - std::wstring str_name(name); + std::string str_name(name); int counter = table->FindCounter(str_name); // Now we can find the location in the table. |