// (No real synchronization needed at destructor time: only one
// thread can be doing this.)
if (!boost::has_trivial_destructor<T>::value) {
- int read = readIndex_;
- int end = writeIndex_;
+ size_t read = readIndex_;
+ size_t end = writeIndex_;
while (read != end) {
records_[read].~T();
if (++read == size_) {
const uint32_t size_;
T* const records_;
- std::atomic<int> readIndex_;
- std::atomic<int> writeIndex_;
+ std::atomic<unsigned int> readIndex_;
+ std::atomic<unsigned int> writeIndex_;
};
}
using namespace folly;
-typedef int ThroughputType;
+typedef unsigned int ThroughputType;
typedef ProducerConsumerQueue<ThroughputType> ThroughputQueueType;
-typedef long LatencyType;
+typedef unsigned long LatencyType;
typedef ProducerConsumerQueue<LatencyType> LatencyQueueType;
template<class QueueType>
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
}
for (int i = 0; i < iters_; ++i) {
- long enqueue_nsec;
+ unsigned long enqueue_nsec;
while (!queue_.read(enqueue_nsec)) {
}
};
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());
}
}
}
struct DtorChecker {
- static int numInstances;
+ static unsigned int numInstances;
DtorChecker() { ++numInstances; }
DtorChecker(const DtorChecker& o) { ++numInstances; }
~DtorChecker() { --numInstances; }
};
-int DtorChecker::numInstances = 0;
+unsigned int DtorChecker::numInstances = 0;
}