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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 // thread is done (terminated), we push it onto this llist. When a new worker | 592 // thread is done (terminated), we push it onto this llist. When a new worker |
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 |
598 // list_lock_ is held. | 603 // The next available worker thread number. This should only be accessed when |
599 static int thread_number_counter_; | 604 // the list_lock_ is held. |
| 605 static int worker_thread_data_creation_count_; |
| 606 |
| 607 // The number of times TLS has called us back to cleanup a ThreadData |
| 608 // instance. This is only accessed while list_lock_ is held. |
| 609 static int cleanup_count_; |
| 610 |
600 // Incarnation sequence number, indicating how many times (during unittests) | 611 // Incarnation sequence number, indicating how many times (during unittests) |
601 // we've either transitioned out of UNINITIALIZED, or into that state. This | 612 // we've either transitioned out of UNINITIALIZED, or into that state. This |
602 // value is only accessed while the list_lock_ is held. | 613 // value is only accessed while the list_lock_ is held. |
603 static int incarnation_counter_; | 614 static int incarnation_counter_; |
| 615 |
604 // Protection for access to all_thread_data_list_head_, and to | 616 // Protection for access to all_thread_data_list_head_, and to |
605 // unregistered_thread_data_pool_. This lock is leaked at shutdown. | 617 // 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 | 618 // The lock is very infrequently used, so we can afford to just make a lazy |
607 // instance and be safe. | 619 // instance and be safe. |
608 static base::LazyInstance<base::Lock, | 620 static base::LazyInstance<base::Lock, |
609 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; | 621 base::LeakyLazyInstanceTraits<base::Lock> > list_lock_; |
610 | 622 |
611 // Record of what the incarnation_counter_ was when this instance was created. | 623 // 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 | 624 // If the incarnation_counter_ has changed, then we avoid pushing into the |
613 // pool (this is only critical in tests which go through multiple | 625 // pool (this is only critical in tests which go through multiple |
614 // incarations). | 626 // incarations). |
615 int incarnation_count_for_pool_; | 627 int incarnation_count_for_pool_; |
616 | 628 |
617 // We set status_ to SHUTDOWN when we shut down the tracking service. | 629 // We set status_ to SHUTDOWN when we shut down the tracking service. |
618 static Status status_; | 630 static Status status_; |
619 | 631 |
(...skipping 28 matching lines...) Expand all Loading... |
648 // It is locked before changing, and hence other threads may access it by | 660 // It is locked before changing, and hence other threads may access it by |
649 // locking before reading it. | 661 // locking before reading it. |
650 DeathMap death_map_; | 662 DeathMap death_map_; |
651 | 663 |
652 // Lock to protect *some* access to BirthMap and DeathMap. The maps are | 664 // 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 | 665 // 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 | 666 // 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 | 667 // 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 | 668 // don't need a lock, as there is no potential for a conflict since the |
657 // writing is only done from this thread. | 669 // writing is only done from this thread. |
658 mutable base::Lock lock_; | 670 mutable base::Lock map_lock_; |
659 | 671 |
660 DISALLOW_COPY_AND_ASSIGN(ThreadData); | 672 DISALLOW_COPY_AND_ASSIGN(ThreadData); |
661 }; | 673 }; |
662 | 674 |
663 //------------------------------------------------------------------------------ | 675 //------------------------------------------------------------------------------ |
664 // Provide simple way to to start global tracking, and to tear down tracking | 676 // 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 | 677 // 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 | 678 // 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. | 679 // destructor, and perhaps this whole class should go away. |
668 | 680 |
(...skipping 11 matching lines...) Expand all Loading... |
680 } | 692 } |
681 | 693 |
682 private: | 694 private: |
683 | 695 |
684 DISALLOW_COPY_AND_ASSIGN(AutoTracking); | 696 DISALLOW_COPY_AND_ASSIGN(AutoTracking); |
685 }; | 697 }; |
686 | 698 |
687 } // namespace tracked_objects | 699 } // namespace tracked_objects |
688 | 700 |
689 #endif // BASE_TRACKED_OBJECTS_H_ | 701 #endif // BASE_TRACKED_OBJECTS_H_ |
OLD | NEW |