27 using namespace folly;
35 for (
size_t i = 0;
i < 100000; ++
i) {
36 auto ptr = pool.allocElem();
41 std::vector<Pool::UniquePtr> leak;
43 auto ptr = pool.allocElem();
54 const int count = 1000;
58 Sched sched(Sched::uniform(0));
63 for (
auto pass = 0; pass < 10; ++pass) {
69 sem_init(&allocSem, 0, poolSize);
74 sem_init(&readSem, 0, 0);
76 std::thread produce = Sched::thread([&]() {
82 idx, poolSize + (pool.NumLocalLists - 1) * pool.LocalListLimit);
85 Sched::post(&readSem);
89 std::thread consume = Sched::thread([&]() {
97 idx, poolSize + (Pool::NumLocalLists - 1) * Pool::LocalListLimit);
99 pool.recycleIndex(idx);
100 Sched::post(&allocSem);
117 EXPECT_EQ(Pool::maxIndexForCapacity(10), 10u);
118 for (
auto i = 0;
i < 10; ++
i) {
129 for (
auto i = 0;
i < 10; ++
i) {
130 threads[
i] = std::thread([&]() {
131 for (
auto j = 0; j < 100; ++j) {
138 for (
auto i = 0;
i < 10; ++
i) {
142 for (
auto i = 0;
i < 16 * 32; ++
i) {
151 for (
auto i = 0;
i < 1000; ++
i) {
154 int* elem = &pool[idx];
172 elem_ = arg1->length() + arg2;
189 for (
size_t i = 0;
i < 10; ++
i) {
191 std::unique_ptr<std::string> arg{
new std::string{
"abc"}};
213 for (
size_t i = 0;
i < 10; ++
i) {
215 auto ptr = pool.allocElem();
227 const int count = 1000;
234 std::vector<std::thread> thr(nthreads);
236 thr[
i] = std::thread([&]() {
237 for (
auto j = 0; j <
count; ++j) {
241 idx, poolSize + (pool.NumLocalLists - 1) * pool.LocalListLimit);
243 pool.recycleIndex(idx);
247 for (
auto&
t : thr) {
265 std::atomic<bool>
start{
false};
266 std::atomic<int> started{0};
279 std::vector<std::thread> thr(nthreads);
281 thr[
i] = std::thread([&]() {
282 started.fetch_add(1);
283 while (!
start.load()) {
286 for (
auto j = 0; j <
count; ++j) {
289 pool.recycleIndex(idx);
300 for (
auto&
t : thr) {
335 instance->onAllocate(ptr, s);
339 instance->onRecycle(ptr);
399 struct IncompleteTestElement;
#define EXPECT_LE(val1, val2)
NonTrivialStruct(std::unique_ptr< std::string > &&arg1, size_t arg2)
void write(const T &in, folly::io::Appender &appender)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
#define EXPECT_GE(val1, val2)
uint32_t locateElem(const T *elem) const
std::vector< std::thread::id > threads
void testTraits(TraitsTestPool &pool)
static void onAllocate(std::string *ptr, std::string s)
static void cleanup(std::string *ptr)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
size_t read(T &out, folly::io::Cursor &cursor)
bool isAllocated(uint32_t idx) const
Returns true iff idx has been alloc()ed and not recycleIndex()ed.
static MockTraits * instance
bool wait(Waiter *waiter, bool shouldSleep, Waiter *&next)
UniquePtr allocElem(Args &&...args)
uint32_t allocIndex(Args &&...args)
static void initialize(std::string *ptr)
TEST(ProgramOptionsTest, Errors)
#define EXPECT_TRUE(condition)
static void onRecycle(std::string *ptr)
#define MOCK_METHOD1(m,...)
#define EXPECT_NE(val1, val2)
void recycleIndex(uint32_t idx)
Gives up ownership previously granted by alloc()
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
#define MOCK_METHOD2(m,...)
int close(NetworkSocket s)
void pipe(CPUExecutor cpu, IOExecutor io)
static FOLLY_TLS size_t count