summaryrefslogtreecommitdiffstats
path: root/base/stats_table.cc
diff options
context:
space:
mode:
authordkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 19:21:34 +0000
committerdkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 19:21:34 +0000
commitbb47a94f2a1e5c9bc7d5e0e40cc64e8b791134a3 (patch)
treedcc51a6445b4d410aea493094b322bdf0dcb31c7 /base/stats_table.cc
parent50b691cc2cfdbb3b39e05c6c1632d6e9276f52d1 (diff)
downloadchromium_src-bb47a94f2a1e5c9bc7d5e0e40cc64e8b791134a3.zip
chromium_src-bb47a94f2a1e5c9bc7d5e0e40cc64e8b791134a3.tar.gz
chromium_src-bb47a94f2a1e5c9bc7d5e0e40cc64e8b791134a3.tar.bz2
Port last remaining test case in base/stats_table_unittest.cc, and
fix the bug it exposes on posix in StatsTable, i.e. UnregisterThread() breaks when called inside SlotReturnFunction() on posix because posix clears tls data before calling destructor. Review URL: http://codereview.chromium.org/8751 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/stats_table.cc')
-rw-r--r--base/stats_table.cc31
1 files changed, 14 insertions, 17 deletions
diff --git a/base/stats_table.cc b/base/stats_table.cc
index 7c55204..47bc533 100644
--- a/base/stats_table.cc
+++ b/base/stats_table.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/platform_thread.h"
+#include "base/process_util.h"
#include "base/shared_memory.h"
#include "base/string_util.h"
#include "base/thread_local_storage.h"
@@ -91,16 +92,6 @@ struct StatsTableTLSData {
int slot;
};
-// The SlotReturnFunction is called at thread exit for each thread
-// which used the StatsTable.
-static void SlotReturnFunction(void* data) {
- StatsTableTLSData* tls_data = static_cast<StatsTableTLSData*>(data);
- if (tls_data) {
- DCHECK(tls_data->table);
- tls_data->table->UnregisterThread();
- }
-}
-
} // namespace
// The StatsTablePrivate maintains convenience pointers into the
@@ -313,12 +304,7 @@ int StatsTable::RegisterThread(const std::wstring& name) {
base::wcslcpy(impl_->thread_name(slot), thread_name.c_str(),
kMaxThreadNameLength);
*(impl_->thread_tid(slot)) = PlatformThread::CurrentId();
- // TODO(pinkerton): these should go into process_utils when it's ported
-#if defined(OS_WIN)
- *(impl_->thread_pid(slot)) = GetCurrentProcessId();
-#elif defined(OS_POSIX)
- *(impl_->thread_pid(slot)) = getpid();
-#endif
+ *(impl_->thread_pid(slot)) = process_util::GetCurrentProcId();
}
// Set our thread local storage.
@@ -341,7 +327,10 @@ StatsTableTLSData* StatsTable::GetTLSData() const {
}
void StatsTable::UnregisterThread() {
- StatsTableTLSData* data = GetTLSData();
+ UnregisterThread(GetTLSData());
+}
+
+void StatsTable::UnregisterThread(StatsTableTLSData* data) {
if (!data)
return;
DCHECK(impl_);
@@ -355,6 +344,14 @@ void StatsTable::UnregisterThread() {
delete data;
}
+void StatsTable::SlotReturnFunction(void* data) {
+ StatsTableTLSData* tls_data = static_cast<StatsTableTLSData*>(data);
+ if (tls_data) {
+ DCHECK(tls_data->table);
+ tls_data->table->UnregisterThread(tls_data);
+ }
+}
+
int StatsTable::CountThreadsRegistered() const {
if (!impl_)
return 0;