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