summaryrefslogtreecommitdiffstats
path: root/base/tracked_objects.h
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 17:03:33 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 17:03:33 +0000
commit445029fbd71d6c7b3fe145c26a76cbdc4c6613d3 (patch)
tree273df6aed06fa05ae69b8834b8c11c43192d8689 /base/tracked_objects.h
parent5183c3fd2be99ea2472112aa924e0ed6d5da8fd9 (diff)
downloadchromium_src-445029fbd71d6c7b3fe145c26a76cbdc4c6613d3.zip
chromium_src-445029fbd71d6c7b3fe145c26a76cbdc4c6613d3.tar.gz
chromium_src-445029fbd71d6c7b3fe145c26a76cbdc4c6613d3.tar.bz2
Avoid any possibility of an Alloc during TLS thread teardown
GIven that TCMalloc might get its thread teardown notifgication ahead of the profiler, we need to be careful to not do an alloc in the teardown handler. If we did, we might bring TCMalloc back to life on this thread... and it might not get a second teardown notification. r=rtenneti BUG=104696 Review URL: http://codereview.chromium.org/8587031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110706 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/tracked_objects.h')
-rw-r--r--base/tracked_objects.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 90ddc7d..dd1c7c4 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -525,10 +525,31 @@ class BASE_EXPORT ThreadData {
// in production code.
friend class TrackedObjectsTest;
- typedef std::stack<const ThreadData*> ThreadDataPool;
+ // Implment a stack that avoids allocations during a push() by having enough
+ // space ahead of time.
+ class ThreadDataPool {
+ public:
+ ThreadDataPool();
+ ~ThreadDataPool();
+
+ // Make sure the stack is large enough to support the indicated number of
+ // elements.
+ void reserve(size_t largest_worker_pool_number);
+
+ bool empty() const;
+ const ThreadData* top() const;
+ void push(const ThreadData* thread_data);
+ void pop();
+
+ private:
+ std::vector<const ThreadData*> stack_;
+ size_t empty_slot_;
+ DISALLOW_COPY_AND_ASSIGN(ThreadDataPool);
+ };
// Worker thread construction creates a name since there is none.
- ThreadData();
+ explicit ThreadData(size_t thread_number);
+
// Message loop based construction should provide a name.
explicit ThreadData(const std::string& suggested_name);
@@ -616,7 +637,9 @@ class BASE_EXPORT ThreadData {
// Indicate if this is a worker thread, and the ThreadData contexts should be
// stored in the unregistered_thread_data_pool_ when not in use.
- bool is_a_worker_thread_;
+ // Value is zero when it is not a worker thread. Value is a positive integer
+ // corresponding to the created thread name if it is a worker thread.
+ size_t worker_thread_number_;
// A map used on each thread to keep track of Births on this thread.
// This map should only be accessed on the thread it was constructed on.