Commit 5a48486f authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

A few minor fixes

Differential Revision: D31755819

fbshipit-source-id: ad32b753efda887e1dae4a7a29749aefa8477e75
parent 15dd0ae3
......@@ -143,14 +143,16 @@ class AtomicReadMostlyMainPtr {
DCHECK(newMain.get() == nullptr)
<< "Invariant should ensure that at most one version is non-null";
newMain.reset(std::move(ptr));
// If order is acq_rel, it should degrade to just release, since this is a
// store rather than an RMW. (Of course, this is such a slow method that we
// don't really care, but precision is its own reward. If TSAN one day
// understands asymmetric barriers, this will also improve its error
// detection here). We get our "acquire-y-ness" from the mutex.
// If order is acq_rel, it should degrade to just release, and if acquire to
// relaxed, since this is a store rather than an RMW. (Of course, this is
// such a slow method that we don't really care, but precision is its own
// reward. If TSAN one day understands asymmetric barriers, this will also
// improve its error detection here). We get our "acquire-y-ness" from the
// mutex.
auto realOrder =
(order == std::memory_order_acq_rel ? std::memory_order_release
: order);
(order == std::memory_order_acq_rel ? std::memory_order_release
: order == std::memory_order_acquire ? std::memory_order_relaxed
: order);
// After this, read-side critical sections can access both versions, but
// new ones will use newMain.
// This is also synchronization point with loads.
......
......@@ -161,16 +161,18 @@ class ExponentialBackoffWithJitter {
decider_(static_cast<Decider2&&>(decider)) {}
Task<void> operator()(exception_wrapper&& ew) & {
using dist = std::normal_distribution<double>;
if (retryCount_ == maxRetries_ || !decider_(ew)) {
co_yield folly::coro::co_error(std::move(ew));
}
++retryCount_;
auto dist = std::normal_distribution<double>(0.0, relativeJitterStdDev_);
// The jitter will be a value between [e^-stdev]
auto jitter = std::exp(dist(randomGen_));
auto jitter = relativeJitterStdDev_ > 0
? std::exp(dist{0., relativeJitterStdDev_}(randomGen_))
: 1.;
auto backoffRep =
jitter * minBackoff_.count() * std::pow(2, retryCount_ - 1u);
......
......@@ -251,11 +251,11 @@ TEST(JemallocHugePageAllocatorTest, STLAllocator) {
// This should work, just won't get huge pages since
// init hasn't been called yet
vec.reserve(100);
EXPECT_NE(nullptr, &vec[0]);
EXPECT_NE(nullptr, vec.data());
// Reserve & initialize, not on huge pages
MyVec vec2(100);
EXPECT_NE(nullptr, &vec[0]);
EXPECT_NE(nullptr, vec.data());
// F14 maps need quite a lot of memory by default
bool initialized = jha::init(4);
......@@ -265,7 +265,7 @@ TEST(JemallocHugePageAllocatorTest, STLAllocator) {
// Reallocate, this time on huge pages
vec.reserve(200);
EXPECT_NE(nullptr, &vec[0]);
EXPECT_NE(nullptr, vec.data());
MyMap map1;
map1[0] = {1, 2, 3};
......@@ -274,7 +274,7 @@ TEST(JemallocHugePageAllocatorTest, STLAllocator) {
map2[0] = {1, 2, 3};
if (initialized) {
EXPECT_TRUE(jha::addressInArena(&vec[0]));
EXPECT_TRUE(jha::addressInArena(vec.data()));
EXPECT_TRUE(jha::addressInArena(&map1[0]));
EXPECT_TRUE(jha::addressInArena(&map1[0][0]));
EXPECT_TRUE(jha::addressInArena(&map2[0]));
......
......@@ -368,24 +368,13 @@ class UDPNotifyClient : public UDPClient {
}
void onRecvMmsg(AsyncUDPSocket& sock) {
std::vector<struct mmsghdr> msgs;
msgs.reserve(numMsgs_);
memset(msgs.data(), 0, sizeof(struct mmsghdr) * numMsgs_);
const socklen_t addrLen = sizeof(struct sockaddr_storage);
const size_t dataSize = 1024;
std::vector<char> buf;
buf.reserve(numMsgs_ * dataSize);
memset(buf.data(), 0, numMsgs_ * dataSize);
std::vector<struct sockaddr_storage> addrs;
addrs.reserve(numMsgs_);
memset(addrs.data(), 0, sizeof(struct sockaddr_storage) * numMsgs_);
std::vector<struct iovec> iovecs;
iovecs.reserve(numMsgs_);
memset(iovecs.data(), 0, sizeof(struct iovec) * numMsgs_);
std::vector<char> buf(numMsgs_ * dataSize);
std::vector<struct mmsghdr> msgs(numMsgs_);
std::vector<struct sockaddr_storage> addrs(numMsgs_);
std::vector<struct iovec> iovecs(numMsgs_);
for (unsigned int i = 0; i < numMsgs_; ++i) {
struct msghdr* msg = &msgs[i].msg_hdr;
......
......@@ -83,9 +83,10 @@ json_pointer::json_pointer(std::vector<std::string> tokens) noexcept
// private, static
bool json_pointer::unescape(std::string& str) {
char const* end = &str[str.size()];
char* out = &str.front();
char const* decode = out;
char* out = &str[0];
char const* begin = out;
char const* end = begin + str.size();
char const* decode = begin;
while (decode < end) {
if (*decode != '~') {
*out++ = *decode++;
......@@ -106,7 +107,7 @@ bool json_pointer::unescape(std::string& str) {
}
decode += 2;
}
str.resize(out - &str.front());
str.resize(out - begin);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment