Sort #include lines
[folly.git] / folly / test / SmallLocksTest.cpp
index 5aef9ea175debcba09864226d995041e8e5a0079..1e71086f74f9bef4ed089cd74d4dc043ece3a881 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 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/SmallLocks.h>
 
-#include <folly/Random.h>
+#include <pthread.h>
 
 #include <cassert>
+#include <condition_variable>
 #include <cstdio>
 #include <mutex>
-#include <condition_variable>
 #include <string>
-#include <vector>
-#include <pthread.h>
-#include <unistd.h>
-
 #include <thread>
+#include <vector>
 
-#include <gtest/gtest.h>
-
+#include <folly/Random.h>
 #include <folly/portability/Asm.h>
+#include <folly/portability/GTest.h>
+#include <folly/portability/Unistd.h>
 
 using folly::MSLGuard;
 using folly::MicroLock;
@@ -72,12 +70,12 @@ void splock_test() {
   const int max = 1000;
   auto rng = folly::ThreadLocalPRNG();
   for (int i = 0; i < max; i++) {
-    folly::asm_pause();
+    folly::asm_volatile_pause();
     MSLGuard g(v.lock);
 
     int first = v.ar[0];
-    for (size_t i = 1; i < sizeof v.ar / sizeof i; ++i) {
-      EXPECT_EQ(first, v.ar[i]);
+    for (size_t j = 1; j < sizeof v.ar / sizeof j; ++j) {
+      EXPECT_EQ(first, v.ar[j]);
     }
 
     int byte = folly::Random::rand32(rng);
@@ -92,8 +90,9 @@ template<class T> struct PslTest {
   PslTest() { lock.init(); }
 
   void doTest() {
-    T ourVal = rand() % (T(1) << (sizeof(T) * 8 - 1));
-    for (int i = 0; i < 10000; ++i) {
+    using UT = typename std::make_unsigned<T>::type;
+    T ourVal = rand() % T(UT(1) << (sizeof(UT) * 8 - 1));
+    for (int i = 0; i < 100; ++i) {
       std::lock_guard<PicoSpinLock<T>> guard(lock);
       lock.setData(ourVal);
       for (int n = 0; n < 10; ++n) {
@@ -231,9 +230,9 @@ TEST(SmallLocks, MicroLock) {
   // affect bits outside the ones MicroLock is defined to affect.
   struct {
     uint8_t a;
-    volatile uint8_t b;
+    std::atomic<uint8_t> b;
     MicroLock alock;
-    volatile uint8_t d;
+    std::atomic<uint8_t> d;
   } x;
 
   uint8_t origB = 'b';