/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <folly/LifoSem.h>
-#include <folly/test/DeterministicSchedule.h>
-#include <thread>
#include <semaphore.h>
-#include <gflags/gflags.h>
-#include <gtest/gtest.h>
+#include <thread>
#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;
a.wait();
++waitCount;
}
- } catch (ShutdownSemError& x) {
+ } catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
}
try {
a.wait();
EXPECT_TRUE(false);
- } catch (ShutdownSemError& x) {
+ } catch (ShutdownSemError&) {
// expected
EXPECT_TRUE(a.isShutdown());
}
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
- asm volatile ("":::"memory");
+ asm_volatile_memory();
}
}
LifoSem sem(iters);
for (size_t n = 0; n < iters; ++n) {
sem.wait();
- asm volatile ("":::"memory");
+ asm_volatile_memory();
}
}
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
sem.post();
- asm volatile ("":::"memory");
+ asm_volatile_memory();
sem.wait();
- asm volatile ("":::"memory");
+ asm_volatile_memory();
}
}
LifoSem sem;
for (size_t n = 0; n < iters; ++n) {
EXPECT_FALSE(sem.tryWait());
- asm volatile ("":::"memory");
+ asm_volatile_memory();
}
}
EXPECT_EQ(sem_destroy(&sem), 0);
}
-static void contendedUse(uint n, int posters, int waiters) {
+static void contendedUse(uint32_t n, int posters, int waiters) {
LifoSemImpl<std::atomic> sem;
std::vector<std::thread> threads;
BENCHMARK_SUSPEND {
for (int t = 0; t < waiters; ++t) {
threads.emplace_back([=,&sem] {
- for (uint i = t; i < n; i += waiters) {
+ for (uint32_t i = t; i < n; i += waiters) {
sem.wait();
}
});
while (!go.load()) {
std::this_thread::yield();
}
- for (uint i = t; i < n; i += posters) {
+ for (uint32_t i = t; i < n; i += posters) {
sem.post();
}
});