text
stringlengths
0
2.2M
EXPECT_EQ(100, value.c);
}
}
});
}
/* sleep override */ std::this_thread::sleep_for(std::chrono::seconds{1});
done.store(true, std::memory_order_relaxed);
for (auto& thread : threads) {
thread.join();
}
}
TEST(LockFreeRingBuffer, cursorComparison) {
LockFreeRingBuffer<int> rb{2};
rb.write(5);
EXPECT_TRUE(rb.currentHead() == rb.currentHead());
EXPECT_FALSE(rb.currentHead() == rb.currentTail());
EXPECT_TRUE(rb.currentHead() != rb.currentTail());
EXPECT_FALSE(rb.currentHead() != rb.currentHead());
EXPECT_TRUE(rb.currentHead() > rb.currentTail());
EXPECT_FALSE(rb.currentTail() > rb.currentHead());
EXPECT_TRUE(rb.currentTail() < rb.currentHead());
EXPECT_FALSE(rb.currentHead() < rb.currentTail());
}
} // namespace folly
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/io/async/EventHandler.h>
#include <sys/eventfd.h>
#include <bitset>
#include <future>
#include <thread>
#include <folly/MPMCQueue.h>
#include <folly/ScopeGuard.h>
#include <folly/io/async/EventBase.h>
#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>
#include <folly/portability/Sockets.h>
using namespace std;
using namespace folly;
using namespace testing;
void runInThreadsAndWait(size_t nthreads, function<void(size_t)> cb) {
vector<thread> threads(nthreads);
for (size_t i = 0; i < nthreads; ++i) {
threads[i] = thread(cb, i);
}
for (size_t i = 0; i < nthreads; ++i) {
threads[i].join();
}
}
void runInThreadsAndWait(vector<function<void()>> cbs) {
runInThreadsAndWait(cbs.size(), [&](size_t k) { cbs[k](); });
}
class EventHandlerMock : public EventHandler {
public:
EventHandlerMock(EventBase* eb, int fd)
: EventHandler(eb, NetworkSocket::fromFd(fd)) {}
// gmock can't mock noexcept methods, so we need an intermediary
MOCK_METHOD1(_handlerReady, void(uint16_t));
void handlerReady(uint16_t events) noexcept override {
_handlerReady(events);
}
};
class EventHandlerTest : public Test {
public:
int efd = 0;
void SetUp() override {
efd = eventfd(0, EFD_SEMAPHORE);
ASSERT_THAT(efd, Gt(0));
}