]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
compressor: use generate_random_number for type="random" 18272/head
authorCasey Bodley <cbodley@redhat.com>
Thu, 12 Oct 2017 16:46:09 +0000 (12:46 -0400)
committerCasey Bodley <cbodley@redhat.com>
Thu, 12 Oct 2017 17:30:16 +0000 (13:30 -0400)
use an existing thread-local random engine instead of constructing,
seeding, and locking a separate engine

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/compressor/Compressor.cc

index dc96a6e2f16f52e91bb3fa2acef70105c41f1dc4..ade3950fd7ee0f7c6cc79bb8d500ff82cd86cc1b 100644 (file)
@@ -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<decltype(mutex)> lock(mutex);
-      alg = dist(engine);
-    }
+    int alg = ceph::util::generate_random_number(0, COMP_ALG_LAST - 1);
     if (alg == COMP_ALG_NONE) {
       return nullptr;
     }