Go to the documentation of this file.
15 #include "absl/random/internal/pool_urbg.h"
23 #include "absl/base/attributes.h"
24 #include "absl/base/call_once.h"
25 #include "absl/base/config.h"
26 #include "absl/base/internal/endian.h"
27 #include "absl/base/internal/raw_logging.h"
28 #include "absl/base/internal/spinlock.h"
29 #include "absl/base/internal/sysinfo.h"
30 #include "absl/base/internal/unaligned_access.h"
31 #include "absl/base/optimization.h"
32 #include "absl/random/internal/randen.h"
33 #include "absl/random/internal/seed_material.h"
34 #include "absl/random/seed_gen_exception.h"
41 namespace random_internal {
50 class RandenPoolEntry {
85 inline uint8_t RandenPoolEntry::Generate<uint8_t>() {
92 inline uint16_t RandenPoolEntry::Generate<uint16_t>() {
99 inline uint32_t RandenPoolEntry::Generate<uint32_t>() {
106 inline uint64_t RandenPoolEntry::Generate<uint64_t>() {
108 if (next_ >=
kState - 1) {
124 size_t remaining = (
kState - next_) *
sizeof(
state_[0]);
129 next_ += (to_copy +
sizeof(
state_[0]) - 1) /
sizeof(
state_[0]);
134 static constexpr
int kPoolSize = 8;
151 static_assert(kPoolSize >= 1,
152 "At least one urbg instance is required for PoolURBG");
156 #ifdef ABSL_HAVE_THREAD_LOCAL
157 static thread_local
int my_pool_id = -1;
159 my_pool_id = (sequence++ % kPoolSize);
163 static pthread_key_t
tid_key = [] {
164 pthread_key_t tmp_key;
165 int err = pthread_key_create(&tmp_key,
nullptr);
178 my_pool_id = (sequence++ % kPoolSize) + 1;
179 int err = pthread_setspecific(
tid_key,
reinterpret_cast<void*
>(my_pool_id));
184 return my_pool_id - 1;
190 RandenPoolEntry* PoolAlignedAlloc() {
198 new char[
sizeof(RandenPoolEntry) +
kAlignment]);
200 void* aligned =
reinterpret_cast<void*
>(
y == 0 ?
x : (
x +
kAlignment -
y));
201 return new (aligned) RandenPoolEntry();
209 void InitPoolURBG() {
210 static constexpr
size_t kSeedSize =
213 uint32_t seed_material[kPoolSize * kSeedSize];
218 for (
int i = 0;
i < kPoolSize;
i++) {
219 shared_pools[
i] = PoolAlignedAlloc();
220 shared_pools[
i]->Init(
226 RandenPoolEntry* GetPoolForCurrentThread() {
228 return shared_pools[GetPoolID()];
233 template <
typename T>
235 auto*
pool = GetPoolForCurrentThread();
236 return pool->Generate<
T>();
239 template <
typename T>
241 auto*
pool = GetPoolForCurrentThread();
#define ABSL_PREDICT_FALSE(x)
static result_type Generate()
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
static constexpr size_t kCapacity
static void Fill(absl::Span< result_type > data)
#define ABSL_CACHELINE_SIZE
static int Init(CMessage *self, PyObject *args, PyObject *kwargs)
void Generate(void *state) const
#define ABSL_NAMESPACE_END
#define T(upbtypeconst, upbtype, ctype, default_value)
void call_once(absl::once_flag &flag, Callable &&fn, Args &&... args)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void ThrowSeedGenException()
static constexpr size_t kState
#define ABSL_NAMESPACE_BEGIN
bool ReadSeedMaterialFromOSEntropy(absl::Span< uint32_t > values)
#define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...)
unsigned __int64 uint64_t
static ABSL_CONST_INIT pthread_key_t tid_key
static constexpr size_t kStateBytes
static constexpr size_t kCapacityBytes
#define ABSL_CACHELINE_ALIGNED
#define ABSL_LOCKS_EXCLUDED(...)
grpc_connectivity_state state_
InternalDescriptorPool * pool
struct absl::SynchWaitParams ABSL_GUARDED_BY[kNSynchEvent]
#define ABSL_RAW_LOG(severity,...)
constexpr Span< T > MakeSpan(T *ptr, size_t size) noexcept
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:44