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

Side by Side Diff: Source/core/timing/MemoryInfo.cpp

Issue 794223003: Cheaper thread-safe atomic initialization of static references. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add type check for initial value Created 5 years, 11 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 void getCachedHeapSize(HeapInfo& info) 53 void getCachedHeapSize(HeapInfo& info)
54 { 54 {
55 maybeUpdate(); 55 maybeUpdate();
56 info = m_info; 56 info = m_info;
57 } 57 }
58 58
59 static HeapSizeCache& forCurrentThread() 59 static HeapSizeCache& forCurrentThread()
60 { 60 {
61 AtomicallyInitializedStatic(ThreadSpecific<HeapSizeCache>*, heapSizeCach e = new ThreadSpecific<HeapSizeCache>); 61 AtomicallyInitializedStaticReference(ThreadSpecific<HeapSizeCache>, heap SizeCache, new ThreadSpecific<HeapSizeCache>);
62 return **heapSizeCache; 62 return *heapSizeCache;
63 } 63 }
64 64
65 private: 65 private:
66 void maybeUpdate() 66 void maybeUpdate()
67 { 67 {
68 // We rate-limit queries to once every twenty minutes to make it more di fficult 68 // We rate-limit queries to once every twenty minutes to make it more di fficult
69 // for attackers to compare memory usage before and after some event. 69 // for attackers to compare memory usage before and after some event.
70 const double TwentyMinutesInSeconds = 20 * 60; 70 const double TwentyMinutesInSeconds = 20 * 60;
71 71
72 double now = monotonicallyIncreasingTime(); 72 double now = monotonicallyIncreasingTime();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 MemoryInfo::MemoryInfo() 140 MemoryInfo::MemoryInfo()
141 { 141 {
142 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled()) 142 if (RuntimeEnabledFeatures::preciseMemoryInfoEnabled())
143 ScriptGCEvent::getHeapSize(m_info); 143 ScriptGCEvent::getHeapSize(m_info);
144 else 144 else
145 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info); 145 HeapSizeCache::forCurrentThread().getCachedHeapSize(m_info);
146 } 146 }
147 147
148 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698