Skip to content

Commit

Permalink
A few minor fixes
Browse files Browse the repository at this point in the history
Differential Revision: D31755819

fbshipit-source-id: ad32b753efda887e1dae4a7a29749aefa8477e75
  • Loading branch information
ot authored and facebook-github-bot committed Oct 19, 2021
1 parent 15dd0ae commit 5a48486
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
16 changes: 9 additions & 7 deletions folly/experimental/AtomicReadMostlyMainPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions folly/experimental/coro/Retry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions folly/experimental/test/JemallocHugePageAllocatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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};
Expand All @@ -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]));
Expand Down
19 changes: 4 additions & 15 deletions folly/io/async/test/AsyncUDPSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions folly/json_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -106,7 +107,7 @@ bool json_pointer::unescape(std::string& str) {
}
decode += 2;
}
str.resize(out - &str.front());
str.resize(out - begin);
return true;
}

Expand Down

0 comments on commit 5a48486

Please sign in to comment.