Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow-up fixups for atomic_t spinlocks #17611

Merged
merged 3 commits into from Sep 15, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/msg/Messenger.cc
@@ -1,12 +1,11 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include <mutex>
#include <random>

#include <netdb.h>

#include "include/types.h"
#include "include/random.h"

#include "Messenger.h"

#include "msg/simple/SimpleMessenger.h"
Expand All @@ -30,14 +29,7 @@ Messenger *Messenger::create(CephContext *cct, const string &type,
{
int r = -1;
if (type == "random") {
static std::random_device seed;
static std::default_random_engine random_engine(seed());

static std::mutex random_lock;
std::lock_guard<std::mutex> lock(random_lock);

std::uniform_int_distribution<> dis(0, 1);
r = dis(random_engine);
r = ceph::util::generate_random_number(0, 1);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The power of libraries!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought a tear to my eye, it did!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind to rename to gen_rand_number? ,to make consistent with rgw naming style (like https://github.com/ceph/ceph/blob/master/src/rgw/rgw_common.cc#L830)

if (r == 0 || type == "simple")
return new SimpleMessenger(cct, name, std::move(lname), nonce);
Expand Down