From acc6960040a5e8b0a7986299156c3c1325619ec4 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 12 Oct 2017 12:46:09 -0400 Subject: [PATCH] compressor: use generate_random_number for type="random" use an existing thread-local random engine instead of constructing, seeding, and locking a separate engine Signed-off-by: Casey Bodley --- src/compressor/Compressor.cc | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/compressor/Compressor.cc b/src/compressor/Compressor.cc index dc96a6e2f16f..ade3950fd7ee 100644 --- a/src/compressor/Compressor.cc +++ b/src/compressor/Compressor.cc @@ -17,6 +17,7 @@ #include "CompressionPlugin.h" #include "Compressor.h" +#include "include/random.h" #include "common/ceph_context.h" #include "common/debug.h" #include "common/dout.h" @@ -76,16 +77,7 @@ CompressorRef Compressor::create(CephContext *cct, const std::string &type) { // support "random" for teuthology testing if (type == "random") { - static std::random_device seed; - static std::default_random_engine engine(seed()); - static ceph::spinlock mutex; - - int alg = COMP_ALG_NONE; - std::uniform_int_distribution<> dist(0, COMP_ALG_LAST - 1); - { - std::lock_guard lock(mutex); - alg = dist(engine); - } + int alg = ceph::util::generate_random_number(0, COMP_ALG_LAST - 1); if (alg == COMP_ALG_NONE) { return nullptr; } -- 2.47.3