From bb47a94f2a1e5c9bc7d5e0e40cc64e8b791134a3 Mon Sep 17 00:00:00 2001 From: "dkegel@google.com" Date: Fri, 31 Oct 2008 19:21:34 +0000 Subject: 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 --- base/stats_table.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'base/stats_table.h') diff --git a/base/stats_table.h b/base/stats_table.h index 8ef529c..48da71a 100644 --- a/base/stats_table.h +++ b/base/stats_table.h @@ -76,11 +76,6 @@ class StatsTable { // returns 0. int RegisterThread(const std::wstring& name); - // Returns the space occupied by a thread in the table. Generally used - // if a thread terminates but the process continues. This function - // does not zero out the thread's counters. - void UnregisterThread(); - // Returns the number of threads currently registered. This is really not // useful except for diagnostics and debugging. int CountThreadsRegistered() const; @@ -137,6 +132,20 @@ class StatsTable { static int* FindLocation(const wchar_t *name); private: + // Returns the space occupied by a thread in the table. Generally used + // if a thread terminates but the process continues. This function + // does not zero out the thread's counters. + // Cannot be used inside a posix tls destructor. + void UnregisterThread(); + + // This variant expects the tls data to be passed in, so it is safe to + // call from inside a posix tls destructor (see doc for pthread_key_create). + void UnregisterThread(StatsTableTLSData* tls_data); + + // The SlotReturnFunction is called at thread exit for each thread + // which used the StatsTable. + static void SlotReturnFunction(void* data); + // Locates a free slot in the table. Returns a number > 0 on success, // or 0 on failure. The caller must hold the shared_memory lock when // calling this function. -- cgit v1.1