projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
A core-cached shared_ptr
[folly.git]
/
folly
/
test
/
LifoSemTests.cpp
diff --git
a/folly/test/LifoSemTests.cpp
b/folly/test/LifoSemTests.cpp
index 6006c10da30d546f031c9e881a98716506b3b358..69e69eeebd0ffcf6ed974210e0910acbc51b5c2c 100644
(file)
--- a/
folly/test/LifoSemTests.cpp
+++ b/
folly/test/LifoSemTests.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
5
Facebook, Inc.
+ * Copyright 201
7
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-15,15
+15,16
@@
*/
#include <folly/LifoSem.h>
*/
#include <folly/LifoSem.h>
-#include <folly/test/DeterministicSchedule.h>
-#include <thread>
#include <semaphore.h>
#include <semaphore.h>
-#include <gflags/gflags.h>
-#include <gtest/gtest.h>
+#include <thread>
#include <folly/Benchmark.h>
#include <folly/Random.h>
#include <folly/Benchmark.h>
#include <folly/Random.h>
+#include <folly/portability/Asm.h>
+#include <folly/portability/GFlags.h>
+#include <folly/portability/GTest.h>
+#include <folly/test/DeterministicSchedule.h>
using namespace folly;
using namespace folly::test;
using namespace folly;
using namespace folly::test;
@@
-195,7
+196,7
@@
TEST(LifoSem, shutdown_race) {
a.wait();
++waitCount;
}
a.wait();
++waitCount;
}
- } catch (ShutdownSemError&
x
) {
+ } catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
}
// expected
EXPECT_TRUE(a.isShutdown());
}
@@
-227,7
+228,7
@@
TEST(LifoSem, shutdown_multi) {
try {
a.wait();
EXPECT_TRUE(false);
try {
a.wait();
EXPECT_TRUE(false);
- } catch (ShutdownSemError&
x
) {
+ } catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
}
// expected
EXPECT_TRUE(a.isShutdown());
}
@@
-318,7
+319,7
@@
BENCHMARK(single_thread_lifo_post, iters) {
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
- asm
volatile ("":::"memory"
);
+ asm
_volatile_memory(
);
}
}
}
}
@@
-326,7
+327,7
@@
BENCHMARK(single_thread_lifo_wait, iters) {
LifoSem sem(iters);
for (size_t n = 0; n < iters; ++n) {
sem.wait();
LifoSem sem(iters);
for (size_t n = 0; n < iters; ++n) {
sem.wait();
- asm
volatile ("":::"memory"
);
+ asm
_volatile_memory(
);
}
}
}
}
@@
-334,9
+335,9
@@
BENCHMARK(single_thread_lifo_postwait, iters) {
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
- asm
volatile ("":::"memory"
);
+ asm
_volatile_memory(
);
sem.wait();
sem.wait();
- asm
volatile ("":::"memory"
);
+ asm
_volatile_memory(
);
}
}
}
}
@@
-344,7
+345,7
@@
BENCHMARK(single_thread_lifo_trywait, iters) {
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
EXPECT_FALSE(sem.tryWait());
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
EXPECT_FALSE(sem.tryWait());
- asm
volatile ("":::"memory"
);
+ asm
_volatile_memory(
);
}
}
}
}
@@
-367,7
+368,7
@@
BENCHMARK(single_thread_posix_trywait, iters) {
EXPECT_EQ(sem_destroy(&sem), 0);
}
EXPECT_EQ(sem_destroy(&sem), 0);
}
-static void contendedUse(uint n, int posters, int waiters) {
+static void contendedUse(uint
32_t
n, int posters, int waiters) {
LifoSemImpl<std::atomic> sem;
std::vector<std::thread> threads;
LifoSemImpl<std::atomic> sem;
std::vector<std::thread> threads;
@@
-376,7
+377,7
@@
static void contendedUse(uint n, int posters, int waiters) {
BENCHMARK_SUSPEND {
for (int t = 0; t < waiters; ++t) {
threads.emplace_back([=,&sem] {
BENCHMARK_SUSPEND {
for (int t = 0; t < waiters; ++t) {
threads.emplace_back([=,&sem] {
- for (uint i = t; i < n; i += waiters) {
+ for (uint
32_t
i = t; i < n; i += waiters) {
sem.wait();
}
});
sem.wait();
}
});
@@
-386,7
+387,7
@@
static void contendedUse(uint n, int posters, int waiters) {
while (!go.load()) {
std::this_thread::yield();
}
while (!go.load()) {
std::this_thread::yield();
}
- for (uint i = t; i < n; i += posters) {
+ for (uint
32_t
i = t; i < n; i += posters) {
sem.post();
}
});
sem.post();
}
});
@@
-411,7
+412,7
@@
BENCHMARK_NAMED_PARAM(contendedUse, 16_to_16, 16, 16)
BENCHMARK_NAMED_PARAM(contendedUse, 32_to_32, 32, 32)
BENCHMARK_NAMED_PARAM(contendedUse, 32_to_1000, 32, 1000)
BENCHMARK_NAMED_PARAM(contendedUse, 32_to_32, 32, 32)
BENCHMARK_NAMED_PARAM(contendedUse, 32_to_1000, 32, 1000)
-// sudo nice -n -20 _build/opt/folly/test/LifoSemTests
\
+// sudo nice -n -20 _build/opt/folly/test/LifoSemTests
// --benchmark --bm_min_iters=10000000 --gtest_filter=-\*
// ============================================================================
// folly/test/LifoSemTests.cpp relative time/iter iters/s
// --benchmark --bm_min_iters=10000000 --gtest_filter=-\*
// ============================================================================
// folly/test/LifoSemTests.cpp relative time/iter iters/s