/*
- * 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.
#pragma once
-#include <gtest/gtest.h>
-
-#include <folly/Foreach.h>
#include <folly/Random.h>
#include <folly/Synchronized.h>
+#include <folly/container/Foreach.h>
+#include <folly/portability/GTest.h>
#include <glog/logging.h>
#include <algorithm>
#include <condition_variable>
EXPECT_EQ(1001, obj.size());
EXPECT_EQ(10, obj.back());
EXPECT_EQ(1000, obj2->size());
-
- UNSYNCHRONIZED(obj) {
- EXPECT_EQ(1001, obj->size());
- }
}
SYNCHRONIZED_CONST (obj) {
EXPECT_EQ(1001, obj.size());
- UNSYNCHRONIZED(obj) {
- EXPECT_EQ(1001, obj->size());
- }
}
SYNCHRONIZED (lockedObj, *&obj) {
// Test lock()
for (size_t n = 0; n < itersPerThread; ++n) {
v.contextualLock()->push_back((itersPerThread * threadIdx) + n);
- sched_yield();
+ std::this_thread::yield();
}
};
runParallel(numThreads, pushNumbers);
v->push_back(2 * threadIdx);
// Aaand test the TIMED_SYNCHRONIZED macro
- for (;;)
+ for (;;) {
TIMED_SYNCHRONIZED(5, lv, v) {
if (lv) {
// Sleep for a random time to ensure we trigger timeouts
++(*numTimeouts.contextualLock());
}
+ }
};
static const size_t numThreads = 100;
};
template <class Mutex> void testInPlaceConstruction() {
- // This won't compile without construct_in_place
- folly::Synchronized<NotCopiableNotMovable> a(
- folly::construct_in_place, 5, "a"
- );
-}
-}
+ // This won't compile without in_place
+ folly::Synchronized<NotCopiableNotMovable> a(folly::in_place, 5, "a");
}
+} // namespace sync_tests
+} // namespace folly