From: Casey Bodley Date: Thu, 12 Oct 2017 16:46:09 +0000 (-0400) Subject: compressor: use generate_random_number for type="random" X-Git-Tag: v13.0.1~578^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F18272%2Fhead;p=ceph.git 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 --- 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; }