]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: move static random engine into function scope 11880/head
authorCasey Bodley <cbodley@redhat.com>
Wed, 9 Nov 2016 19:10:42 +0000 (14:10 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 9 Nov 2016 19:10:45 +0000 (14:10 -0500)
this avoids polling the random_device unless it's being used

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

index b17f1ecb8c5cdc468e37cd038fe90d247b999972..f52b243020d7d0c29c045c8d3aff10582c47293d 100644 (file)
@@ -20,16 +20,16 @@ Messenger *Messenger::create_client_messenger(CephContext *cct, string lname)
                           lname, nonce, 0);
 }
 
-static std::random_device seed;
-static std::default_random_engine random_engine(seed());
-static Spinlock random_lock;
-
 Messenger *Messenger::create(CephContext *cct, const string &type,
                             entity_name_t name, string lname,
                             uint64_t nonce, uint64_t cflags)
 {
   int r = -1;
   if (type == "random") {
+    static std::random_device seed;
+    static std::default_random_engine random_engine(seed());
+    static Spinlock random_lock;
+
     std::lock_guard<Spinlock> lock(random_lock);
     std::uniform_int_distribution<> dis(0, 1);
     r = dis(random_engine);