mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:41:45 +00:00
59aa375d22
As part of making the compiler independent of the current isolate (since JITed code will be shared across all isolate) we make the compiler not depend on `Isolate::random()` but rahter on `IsolateGroup::random()`. Issue https://github.com/dart-lang/sdk/issues/36097 TEST=Refactoring of existing code. Change-Id: I4a7bdd5c3e3d7ca83ef828ad6e38f117b5f2e9ce Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182560 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
43 lines
894 B
C++
43 lines
894 B
C++
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_VM_RANDOM_H_
|
|
#define RUNTIME_VM_RANDOM_H_
|
|
|
|
#include <atomic>
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/flags.h"
|
|
#include "vm/globals.h"
|
|
|
|
namespace dart {
|
|
|
|
DECLARE_FLAG(uint64_t, random_seed);
|
|
|
|
class Random {
|
|
public:
|
|
Random();
|
|
// Seed must be non-zero.
|
|
explicit Random(uint64_t seed);
|
|
~Random();
|
|
|
|
uint32_t NextUInt32();
|
|
uint64_t NextUInt64() {
|
|
return (static_cast<uint64_t>(NextUInt32()) << 32) |
|
|
static_cast<uint64_t>(NextUInt32());
|
|
}
|
|
|
|
private:
|
|
uint64_t NextState();
|
|
void Initialize(uint64_t seed);
|
|
|
|
std::atomic<uint64_t> _state;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Random);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_RANDOM_H_
|