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

Side by Side Diff: base/tracked_objects.h

Issue 2667513003: Remove some LazyInstance use in base/ (Closed)
Patch Set: . Created 3 years, 10 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <stack> 12 #include <stack>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/allocator/features.h" 17 #include "base/allocator/features.h"
18 #include "base/atomicops.h" 18 #include "base/atomicops.h"
19 #include "base/base_export.h" 19 #include "base/base_export.h"
20 #include "base/containers/hash_tables.h" 20 #include "base/containers/hash_tables.h"
21 #include "base/debug/debugging_flags.h" 21 #include "base/debug/debugging_flags.h"
22 #include "base/debug/thread_heap_usage_tracker.h" 22 #include "base/debug/thread_heap_usage_tracker.h"
23 #include "base/gtest_prod_util.h" 23 #include "base/gtest_prod_util.h"
24 #include "base/lazy_instance.h"
25 #include "base/location.h" 24 #include "base/location.h"
26 #include "base/macros.h" 25 #include "base/macros.h"
27 #include "base/process/process_handle.h" 26 #include "base/process/process_handle.h"
28 #include "base/profiler/tracked_time.h" 27 #include "base/profiler/tracked_time.h"
29 #include "base/synchronization/lock.h" 28 #include "base/synchronization/lock.h"
30 #include "base/threading/thread_checker.h" 29 #include "base/threading/thread_checker.h"
31 #include "base/threading/thread_local_storage.h" 30 #include "base/threading/thread_local_storage.h"
32 31
33 namespace base { 32 namespace base {
34 struct TrackingInfo; 33 struct TrackingInfo;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // name without trailing digits) as the current thread is available, it is 118 // name without trailing digits) as the current thread is available, it is
120 // reused. Otherwise, a new ThreadData instance is instantiated. Since a 119 // reused. Otherwise, a new ThreadData instance is instantiated. Since a
121 // ThreadData is bound to at most one thread at a time, there is no need to 120 // ThreadData is bound to at most one thread at a time, there is no need to
122 // acquire a lock to access its maps. Over time, a ThreadData may be bound to 121 // acquire a lock to access its maps. Over time, a ThreadData may be bound to
123 // different threads that share the same sanitized name. 122 // different threads that share the same sanitized name.
124 // 123 //
125 // We maintain a list of all ThreadData instances for the current process. Each 124 // We maintain a list of all ThreadData instances for the current process. Each
126 // ThreadData instance has a pointer to the next one. A static member of 125 // ThreadData instance has a pointer to the next one. A static member of
127 // ThreadData provides a pointer to the first item on this global list, and 126 // ThreadData provides a pointer to the first item on this global list, and
128 // access via that all_thread_data_list_head_ item requires the use of the 127 // access via that all_thread_data_list_head_ item requires the use of the
129 // list_lock_. 128 // ListLock().
130 // 129 //
131 // When new ThreadData instances are added to the global list, they are pre- 130 // When new ThreadData instances are added to the global list, they are pre-
132 // pended, which ensures that any prior acquisition of the list is valid (i.e., 131 // pended, which ensures that any prior acquisition of the list is valid (i.e.,
133 // the holder can iterate over it without fear of it changing, or the necessity 132 // the holder can iterate over it without fear of it changing, or the necessity
134 // of using an additional lock. Iterations are actually pretty rare (used 133 // of using an additional lock. Iterations are actually pretty rare (used
135 // primarily for cleanup, or snapshotting data for display), so this lock has 134 // primarily for cleanup, or snapshotting data for display), so this lock has
136 // very little global performance impact. 135 // very little global performance impact.
137 // 136 //
138 // The above description tries to define the high performance (run time) 137 // The above description tries to define the high performance (run time)
139 // portions of these classes. After gathering statistics, calls instigated 138 // portions of these classes. After gathering statistics, calls instigated
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 708
710 // When non-null, this specifies an external function that supplies monotone 709 // When non-null, this specifies an external function that supplies monotone
711 // increasing time functcion. 710 // increasing time functcion.
712 static NowFunction* now_function_for_testing_; 711 static NowFunction* now_function_for_testing_;
713 712
714 // We use thread local store to identify which ThreadData to interact with. 713 // We use thread local store to identify which ThreadData to interact with.
715 static base::ThreadLocalStorage::StaticSlot tls_index_; 714 static base::ThreadLocalStorage::StaticSlot tls_index_;
716 715
717 // Linked list of ThreadData instances that were associated with threads that 716 // Linked list of ThreadData instances that were associated with threads that
718 // have been terminated and that have not been associated with a new thread 717 // have been terminated and that have not been associated with a new thread
719 // since then. This is only accessed while |list_lock_| is held. 718 // since then. This is only accessed while |ListLock()| is held.
720 static ThreadData* first_retired_thread_data_; 719 static ThreadData* first_retired_thread_data_;
721 720
722 // Link to the most recently created instance (starts a null terminated list). 721 // Link to the most recently created instance (starts a null terminated list).
723 // The list is traversed by about:profiler when it needs to snapshot data. 722 // The list is traversed by about:profiler when it needs to snapshot data.
724 // This is only accessed while list_lock_ is held. 723 // This is only accessed while ListLock() is held.
725 static ThreadData* all_thread_data_list_head_; 724 static ThreadData* all_thread_data_list_head_;
726 725
727 // The number of times TLS has called us back to cleanup a ThreadData 726 // The number of times TLS has called us back to cleanup a ThreadData
728 // instance. This is only accessed while list_lock_ is held. 727 // instance. This is only accessed while ListLock() is held.
729 static int cleanup_count_; 728 static int cleanup_count_;
730 729
731 // Incarnation sequence number, indicating how many times (during unittests) 730 // Incarnation sequence number, indicating how many times (during unittests)
732 // we've either transitioned out of UNINITIALIZED, or into that state. This 731 // we've either transitioned out of UNINITIALIZED, or into that state. This
733 // value is only accessed while the list_lock_ is held. 732 // value is only accessed while the ListLock() is held.
734 static int incarnation_counter_; 733 static int incarnation_counter_;
735 734
736 // Protection for access to all_thread_data_list_head_, and to 735 // Protection for access to all_thread_data_list_head_, and to
737 // unregistered_thread_data_pool_. This lock is leaked at shutdown. 736 // unregistered_thread_data_pool_. This lock is leaked at shutdown.
738 // The lock is very infrequently used, so we can afford to just make a lazy 737 // The lock is very infrequently used, so we can afford to just make a lazy
739 // instance and be safe. 738 // instance and be safe.
740 static base::LazyInstance<base::Lock>::Leaky list_lock_; 739 static base::Lock* ListLock() {
740 static auto lock = new base::Lock();
741 return lock;
742 }
741 743
742 // We set status_ to SHUTDOWN when we shut down the tracking service. 744 // We set status_ to SHUTDOWN when we shut down the tracking service.
743 static base::subtle::Atomic32 status_; 745 static base::subtle::Atomic32 status_;
744 746
745 // Link to next instance (null terminated list). Used to globally track all 747 // Link to next instance (null terminated list). Used to globally track all
746 // registered instances (corresponds to all registered threads where we keep 748 // registered instances (corresponds to all registered threads where we keep
747 // data). Only modified in the constructor. 749 // data). Only modified in the constructor.
748 ThreadData* next_; 750 ThreadData* next_;
749 751
750 // Pointer to another retired ThreadData instance. This value is nullptr if 752 // Pointer to another retired ThreadData instance. This value is nullptr if
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 ProcessDataSnapshot(const ProcessDataSnapshot& other); 891 ProcessDataSnapshot(const ProcessDataSnapshot& other);
890 ~ProcessDataSnapshot(); 892 ~ProcessDataSnapshot();
891 893
892 PhasedProcessDataSnapshotMap phased_snapshots; 894 PhasedProcessDataSnapshotMap phased_snapshots;
893 base::ProcessId process_id; 895 base::ProcessId process_id;
894 }; 896 };
895 897
896 } // namespace tracked_objects 898 } // namespace tracked_objects
897 899
898 #endif // BASE_TRACKED_OBJECTS_H_ 900 #endif // BASE_TRACKED_OBJECTS_H_
OLDNEW
« base/cpu.cc ('K') | « base/trace_event/trace_log.cc ('k') | base/tracked_objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698