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

Side by Side Diff: base/tracked_objects.h

Issue 8587031: Avoid any possibility of an Alloc during TLS thread teardown (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/tracked_objects.cc » ('j') | base/tracked_objects.cc » ('J')
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 #ifndef BASE_TRACKED_OBJECTS_H_ 5 #ifndef BASE_TRACKED_OBJECTS_H_
6 #define BASE_TRACKED_OBJECTS_H_ 6 #define BASE_TRACKED_OBJECTS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <stack> 10 #include <stack>
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // the profiler enabled. It will generally be optimized away when it is 518 // the profiler enabled. It will generally be optimized away when it is
519 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of 519 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of
520 // the code). 520 // the code).
521 static TrackedTime Now(); 521 static TrackedTime Now();
522 522
523 private: 523 private:
524 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it 524 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it
525 // in production code. 525 // in production code.
526 friend class TrackedObjectsTest; 526 friend class TrackedObjectsTest;
527 527
528 typedef std::stack<const ThreadData*> ThreadDataPool; 528 // Implment a stack that avoids allocations during a push() by having enough
ramant (doing other things) 2011/11/17 22:59:36 nit: Implment -> Implement
529 // space ahead of time.
530 class ThreadDataPool {
531 public:
532 ThreadDataPool();
533 ~ThreadDataPool();
534
535 // Make sure the stack is large enough to support the indicated number of
536 // elements.
537 void reserve(size_t largest_worker_pool_number);
538
539 bool empty() const;
540 const ThreadData* top() const;
541 void push(const ThreadData* thread_data);
542 void pop();
543
544 private:
545 std::vector<const ThreadData*> stack_;
546 size_t empty_slot_;
547 DISALLOW_COPY_AND_ASSIGN(ThreadDataPool);
548 };
529 549
530 // Worker thread construction creates a name since there is none. 550 // Worker thread construction creates a name since there is none.
531 ThreadData(); 551 explicit ThreadData(size_t thread_number);
552
532 // Message loop based construction should provide a name. 553 // Message loop based construction should provide a name.
533 explicit ThreadData(const std::string& suggested_name); 554 explicit ThreadData(const std::string& suggested_name);
534 555
535 ~ThreadData(); 556 ~ThreadData();
536 557
537 // Push this instance to the head of all_thread_data_list_head_, linking it to 558 // Push this instance to the head of all_thread_data_list_head_, linking it to
538 // the previous head. This is performed after each construction, and leaves 559 // the previous head. This is performed after each construction, and leaves
539 // the instance permanently on that list. 560 // the instance permanently on that list.
540 void PushToHeadOfList(); 561 void PushToHeadOfList();
541 562
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // registered instances (corresponds to all registered threads where we keep 630 // registered instances (corresponds to all registered threads where we keep
610 // data). 631 // data).
611 ThreadData* next_; 632 ThreadData* next_;
612 633
613 // The name of the thread that is being recorded. If this thread has no 634 // The name of the thread that is being recorded. If this thread has no
614 // message_loop, then this is a worker thread, with a sequence number postfix. 635 // message_loop, then this is a worker thread, with a sequence number postfix.
615 std::string thread_name_; 636 std::string thread_name_;
616 637
617 // Indicate if this is a worker thread, and the ThreadData contexts should be 638 // Indicate if this is a worker thread, and the ThreadData contexts should be
618 // stored in the unregistered_thread_data_pool_ when not in use. 639 // stored in the unregistered_thread_data_pool_ when not in use.
619 bool is_a_worker_thread_; 640 // Value is zero when it is not a worker thread. Value is a positive integer
641 // corresponding to the created thread name if it is a worker thread.
642 size_t worker_thread_number_;
620 643
621 // A map used on each thread to keep track of Births on this thread. 644 // A map used on each thread to keep track of Births on this thread.
622 // This map should only be accessed on the thread it was constructed on. 645 // This map should only be accessed on the thread it was constructed on.
623 // When a snapshot is needed, this structure can be locked in place for the 646 // When a snapshot is needed, this structure can be locked in place for the
624 // duration of the snapshotting activity. 647 // duration of the snapshotting activity.
625 BirthMap birth_map_; 648 BirthMap birth_map_;
626 649
627 // Similar to birth_map_, this records informations about death of tracked 650 // Similar to birth_map_, this records informations about death of tracked
628 // instances (i.e., when a tracked instance was destroyed on this thread). 651 // instances (i.e., when a tracked instance was destroyed on this thread).
629 // It is locked before changing, and hence other threads may access it by 652 // It is locked before changing, and hence other threads may access it by
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } 684 }
662 685
663 private: 686 private:
664 687
665 DISALLOW_COPY_AND_ASSIGN(AutoTracking); 688 DISALLOW_COPY_AND_ASSIGN(AutoTracking);
666 }; 689 };
667 690
668 } // namespace tracked_objects 691 } // namespace tracked_objects
669 692
670 #endif // BASE_TRACKED_OBJECTS_H_ 693 #endif // BASE_TRACKED_OBJECTS_H_
OLDNEW
« no previous file with comments | « no previous file | base/tracked_objects.cc » ('j') | base/tracked_objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698