/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include "folly/ProducerConsumerQueue.h"
+#include <folly/ProducerConsumerQueue.h>
-#include <gtest/gtest.h>
-#include <vector>
#include <atomic>
#include <chrono>
#include <memory>
#include <thread>
+#include <vector>
+
#include <glog/logging.h>
+#include <folly/portability/GTest.h>
+
//////////////////////////////////////////////////////////////////////
namespace {
};
template<> struct TestTraits<std::string> {
- int limit() const { return 1 << 22; }
+ unsigned int limit() const { return 1 << 22; }
std::string generate() const { return std::string(12, ' '); }
};
}
void producer() {
- for (int i = 0; i < traits_.limit(); ++i) {
+ // This is written differently than you might expect so that
+ // it does not run afoul of -Wsign-compare, regardless of the
+ // signedness of this loop's upper bound.
+ for (auto i = traits_.limit(); i > 0; --i) {
while (!queue_.write(traits_.generate())) {
}
}
{
const size_t testSize = traits_.limit();
testData_.reserve(testSize);
- for (int i = 0; i < testSize; ++i) {
+ for (size_t i = 0; i < testSize; ++i) {
testData_.push_back(traits_.generate());
}
}
} else {
goto again;
}
+ EXPECT_EQ(*data, expect);
} else {
+ EXPECT_EQ(*data, expect);
queue_.popFront();
}
-
- EXPECT_EQ(*data, expect);
}
}
}
struct DtorChecker {
- static int numInstances;
+ static unsigned int numInstances;
DtorChecker() { ++numInstances; }
- DtorChecker(const DtorChecker& o) { ++numInstances; }
+ DtorChecker(const DtorChecker& /* o */) { ++numInstances; }
~DtorChecker() { --numInstances; }
};
-int DtorChecker::numInstances = 0;
+unsigned int DtorChecker::numInstances = 0;
}