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

Side by Side Diff: runtime/vm/random.cc

Issue 1807293002: - Fix for issue 25950 (add registration of a thread exit callback) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 9 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
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/random.h" 5 #include "vm/random.h"
6 #include "vm/dart.h"
6 #include "vm/flags.h" 7 #include "vm/flags.h"
7 #include "vm/isolate.h" 8 #include "vm/os.h"
8 9
9 namespace dart { 10 namespace dart {
10 11
11 DEFINE_FLAG(int, random_seed, 0, "Override the random seed for debugging."); 12 DEFINE_FLAG(int, random_seed, 0, "Override the random seed for debugging.");
12 13
13 Random::Random() { 14 Random::Random() {
14 uint64_t seed = FLAG_random_seed; 15 uint64_t seed = FLAG_random_seed;
15 if (seed == 0) { 16 if (seed == 0) {
16 Dart_EntropySource callback = Isolate::entropy_source_callback(); 17 Dart_EntropySource callback = Dart::entropy_source_callback();
17 if (callback != NULL) { 18 if (callback != NULL) {
18 if (!callback(reinterpret_cast<uint8_t*>(&seed), sizeof(seed))) { 19 if (!callback(reinterpret_cast<uint8_t*>(&seed), sizeof(seed))) {
19 // Callback failed. Reset the seed to 0. 20 // Callback failed. Reset the seed to 0.
20 seed = 0; 21 seed = 0;
21 } 22 }
22 } 23 }
23 } 24 }
24 if (seed == 0) { 25 if (seed == 0) {
25 // We did not get a seed so far. As a fallback we do use the current time. 26 // We did not get a seed so far. As a fallback we do use the current time.
26 seed = OS::GetCurrentTimeMicros(); 27 seed = OS::GetCurrentTimeMicros();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 63 }
63 64
64 65
65 uint32_t Random::NextUInt32() { 66 uint32_t Random::NextUInt32() {
66 const uint64_t MASK_32 = 0xffffffff; 67 const uint64_t MASK_32 = 0xffffffff;
67 NextState(); 68 NextState();
68 return static_cast<uint32_t>(_state & MASK_32); 69 return static_cast<uint32_t>(_state & MASK_32);
69 } 70 }
70 71
71 } // namespace dart 72 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698