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

Side by Side Diff: Source/wtf/CryptographicallyRandomNumber.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) 1996, David Mazieres <dm@uun.org> 2 * Copyright (c) 1996, David Mazieres <dm@uun.org>
3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
4 * 4 *
5 * Permission to use, copy, modify, and distribute this software for any 5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above 6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies. 7 * copyright notice and this permission notice appear in all copies.
8 * 8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 stirIfNeeded(); 158 stirIfNeeded();
159 while (length--) { 159 while (length--) {
160 m_count--; 160 m_count--;
161 stirIfNeeded(); 161 stirIfNeeded();
162 result[length] = getByte(); 162 result[length] = getByte();
163 } 163 }
164 } 164 }
165 165
166 ARC4RandomNumberGenerator& sharedRandomNumberGenerator() 166 ARC4RandomNumberGenerator& sharedRandomNumberGenerator()
167 { 167 {
168 AtomicallyInitializedStatic(ARC4RandomNumberGenerator*, randomNumberGenerato r = new ARC4RandomNumberGenerator); 168 AtomicallyInitializedStaticReference(ARC4RandomNumberGenerator, randomNumber Generator, new ARC4RandomNumberGenerator);
169 return *randomNumberGenerator; 169 return randomNumberGenerator;
170 } 170 }
171 171
172 } 172 }
173 173
174 174
175 uint32_t cryptographicallyRandomNumber() 175 uint32_t cryptographicallyRandomNumber()
176 { 176 {
177 return sharedRandomNumberGenerator().randomNumber(); 177 return sharedRandomNumberGenerator().randomNumber();
178 } 178 }
179 179
180 void cryptographicallyRandomValues(void* buffer, size_t length) 180 void cryptographicallyRandomValues(void* buffer, size_t length)
181 { 181 {
182 sharedRandomNumberGenerator().randomValues(buffer, length); 182 sharedRandomNumberGenerator().randomValues(buffer, length);
183 } 183 }
184 184
185 } 185 }
OLDNEW
« no previous file with comments | « Source/wtf/Atomics.h ('k') | Source/wtf/HashTable.cpp » ('j') | Source/wtf/Threading.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698