OLD | NEW |
---|---|
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 // accumulated outside of execution of tracked runs. | 525 // accumulated outside of execution of tracked runs. |
526 static TrackedTime NowForStartOfRun(); | 526 static TrackedTime NowForStartOfRun(); |
527 static TrackedTime NowForEndOfRun(); | 527 static TrackedTime NowForEndOfRun(); |
528 | 528 |
529 // Provide a time function that does nothing (runs fast) when we don't have | 529 // Provide a time function that does nothing (runs fast) when we don't have |
530 // the profiler enabled. It will generally be optimized away when it is | 530 // the profiler enabled. It will generally be optimized away when it is |
531 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of | 531 // ifdef'ed to be small enough (allowing the profiler to be "compiled out" of |
532 // the code). | 532 // the code). |
533 static TrackedTime Now(); | 533 static TrackedTime Now(); |
534 | 534 |
535 // This function can be called at process termination to validate that thread | |
536 // cleanup routines have been called for at least some number of named | |
537 // threads. | |
538 static void EnsureCleanupWasCalled(int major_threads_shutdown_count); | |
539 | |
535 private: | 540 private: |
536 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it | 541 // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it |
537 // in production code. | 542 // in production code. |
538 friend class TrackedObjectsTest; | 543 friend class TrackedObjectsTest; |
539 | 544 |
540 // Worker thread construction creates a name since there is none. | 545 // Worker thread construction creates a name since there is none. |
541 explicit ThreadData(int thread_number); | 546 explicit ThreadData(int thread_number); |
542 | 547 |
543 // Message loop based construction should provide a name. | 548 // Message loop based construction should provide a name. |
544 explicit ThreadData(const std::string& suggested_name); | 549 explicit ThreadData(const std::string& suggested_name); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 // thread is created, we first try to re-use a ThreadData instance from the | 593 // thread is created, we first try to re-use a ThreadData instance from the |
589 // list, and if none are available, construct a new one. | 594 // list, and if none are available, construct a new one. |
590 // This is only accessed while list_lock_ is held. | 595 // This is only accessed while list_lock_ is held. |
591 static ThreadData* first_retired_worker_; | 596 static ThreadData* first_retired_worker_; |
592 | 597 |
593 // Link to the most recently created instance (starts a null terminated list). | 598 // Link to the most recently created instance (starts a null terminated list). |
594 // The list is traversed by about:profiler when it needs to snapshot data. | 599 // The list is traversed by about:profiler when it needs to snapshot data. |
595 // This is only accessed while list_lock_ is held. | 600 // This is only accessed while list_lock_ is held. |
596 static ThreadData* all_thread_data_list_head_; | 601 static ThreadData* all_thread_data_list_head_; |
597 // The next available thread number. This should only be accessed when the | 602 // The next available thread number. This should only be accessed when the |
598 // list_lock_ is held. | 603 // list_lock_ is held. |
ramant (doing other things)
2011/11/21 04:14:06
nit: should we consider adjusting comments?
jar (doing other things)
2011/11/21 17:22:30
Done.
| |
599 static int thread_number_counter_; | 604 static int worker_thread_data_creation_count_; |
605 // The number of times TLS has called us back to cleanup a ThreadData | |
606 // instance. This is only accessed while list_lock_ is held. | |
607 static int cleanup_count_; | |
600 // Incarnation sequence number, indicating how many times (during unittests) | 608 // Incarnation sequence number, indicating how many times (during unittests) |
601 // we've either transitioned out of UNINITIALIZED, or into that state. This | 609 // we've either transitioned out of UNINITIALIZED, or into that state. This |
602 // value is only accessed while the list_lock_ is held. | 610 // value is only accessed while the list_lock_ is held. |
603 static int incarnation_counter_; | 611 static int incarnation_counter_; |
604 // Protection for access to all_thread_data_list_head_, and to | 612 // Protection for access to all_thread_data_list_head_, and to |
605 // unregistered_thread_data_pool_. This lock is leaked at shutdown. | 613 // unregistered_thread_data_pool_. This lock is leaked at shutdown. |
606 // The lock is very infrequently used, so we can afford to just make a lazy | 614 // The lock is very infrequently used, so we can afford to just make a lazy |
607 // instance and be safe. | 615 // instance and be safe. |
608 static base::LazyInstance<base::Lock, | 616 static base::LazyInstance<base::Lock, |
609 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; | 617 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; |
610 | 618 |
611 // Record of what the incarnation_counter_ was when this instance was created. | 619 // Record of what the incarnation_counter_ was when this instance was created. |
612 // If the incarnation_counter_ has changed, then we avoid pushing into the | 620 // If the incarnation_counter_ has changed, then we avoid pushing into the |
613 // pool (this is only critical in tests which go through multiple | 621 // pool (this is only critical in tests which go through multiple |
614 // incarations). | 622 // incarations). |
615 int incarnation_count_for_pool_; | 623 int incarnation_count_for_pool_; |
616 | 624 |
617 // We set status_ to SHUTDOWN when we shut down the tracking service. | 625 // We set status_ to SHUTDOWN when we shut down the tracking service. |
618 static Status status_; | 626 static Status status_; |
619 | 627 |
(...skipping 28 matching lines...) Expand all Loading... | |
648 // It is locked before changing, and hence other threads may access it by | 656 // It is locked before changing, and hence other threads may access it by |
649 // locking before reading it. | 657 // locking before reading it. |
650 DeathMap death_map_; | 658 DeathMap death_map_; |
651 | 659 |
652 // Lock to protect *some* access to BirthMap and DeathMap. The maps are | 660 // Lock to protect *some* access to BirthMap and DeathMap. The maps are |
653 // regularly read and written on this thread, but may only be read from other | 661 // regularly read and written on this thread, but may only be read from other |
654 // threads. To support this, we acquire this lock if we are writing from this | 662 // threads. To support this, we acquire this lock if we are writing from this |
655 // thread, or reading from another thread. For reading from this thread we | 663 // thread, or reading from another thread. For reading from this thread we |
656 // don't need a lock, as there is no potential for a conflict since the | 664 // don't need a lock, as there is no potential for a conflict since the |
657 // writing is only done from this thread. | 665 // writing is only done from this thread. |
658 mutable base::Lock lock_; | 666 mutable base::Lock map_lock_; |
659 | 667 |
660 DISALLOW_COPY_AND_ASSIGN(ThreadData); | 668 DISALLOW_COPY_AND_ASSIGN(ThreadData); |
661 }; | 669 }; |
662 | 670 |
663 //------------------------------------------------------------------------------ | 671 //------------------------------------------------------------------------------ |
664 // Provide simple way to to start global tracking, and to tear down tracking | 672 // Provide simple way to to start global tracking, and to tear down tracking |
665 // when done. The design has evolved to *not* do any teardown (and just leak | 673 // when done. The design has evolved to *not* do any teardown (and just leak |
666 // all allocated data structures). As a result, we don't have any code in this | 674 // all allocated data structures). As a result, we don't have any code in this |
667 // destructor, and perhaps this whole class should go away. | 675 // destructor, and perhaps this whole class should go away. |
668 | 676 |
(...skipping 11 matching lines...) Expand all Loading... | |
680 } | 688 } |
681 | 689 |
682 private: | 690 private: |
683 | 691 |
684 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 692 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
685 }; | 693 }; |
686 | 694 |
687 } // namespace tracked_objects | 695 } // namespace tracked_objects |
688 | 696 |
689 #endif // BASE_TRACKED_OBJECTS_H_ | 697 #endif // BASE_TRACKED_OBJECTS_H_ |
OLD | NEW |