Commit e2886185 authored by Michael Park's avatar Michael Park Committed by Facebook GitHub Bot

Remove `TIMED_SYNCHRONIZED(_CONST)` and replace its usage with `wlock`/`rlock` functions.

Summary: This macro has been deprecated and given that there are not that many uses, it seems relatively simple to remove it entirely.

Reviewed By: yfeldblum, aary

Differential Revision: D16904736

fbshipit-source-id: 56daffd480c586be2a5636b3ce20c6fe1d5ea018
parent 266c62de
......@@ -1822,26 +1822,6 @@ struct [[deprecated(
SYNCHRONIZED_VAR(state) = true) \
FOLLY_POP_WARNING
/**
* NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock
* functions instead. In the future it will be marked with a deprecation
* attribute to emit build-time warnings, and then it will be removed entirely.
*/
#define TIMED_SYNCHRONIZED(timeout, ...) \
if (bool SYNCHRONIZED_VAR(state) = false) { \
::folly::detail::SYNCHRONIZED_macro_is_deprecated{}; \
} else \
for (auto SYNCHRONIZED_VAR(lockedPtr) = \
(FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))).timedAcquire(timeout); \
!SYNCHRONIZED_VAR(state); \
SYNCHRONIZED_VAR(state) = true) \
for (auto FB_VA_GLUE(FB_ARG_1, (__VA_ARGS__)) = \
(!SYNCHRONIZED_VAR(lockedPtr) \
? nullptr \
: SYNCHRONIZED_VAR(lockedPtr).operator->()); \
!SYNCHRONIZED_VAR(state); \
SYNCHRONIZED_VAR(state) = true)
/**
* NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock
* functions instead. In the future it will be marked with a deprecation
......@@ -1854,19 +1834,6 @@ struct [[deprecated(
FB_VA_GLUE(FB_ARG_1, (__VA_ARGS__)), \
as_const(FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))))
/**
* NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock
* functions instead. In the future it will be marked with a deprecation
* attribute to emit build-time warnings, and then it will be removed entirely.
*
* Similar to TIMED_SYNCHRONIZED, but only uses a read lock.
*/
#define TIMED_SYNCHRONIZED_CONST(timeout, ...) \
TIMED_SYNCHRONIZED( \
timeout, \
FB_VA_GLUE(FB_ARG_1, (__VA_ARGS__)), \
as_const(FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))))
/**
* NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock
* functions instead. In the future it will be marked with a deprecation
......
......@@ -121,10 +121,6 @@ TYPED_TEST(SynchronizedTimedTest, Timed) {
testTimed<TypeParam>();
}
TYPED_TEST(SynchronizedTimedTest, TimedSynchronized) {
testTimedSynchronized<TypeParam>();
}
template <class Mutex>
class SynchronizedTimedWithConstTest : public testing::Test {};
......@@ -143,10 +139,6 @@ TYPED_TEST(SynchronizedTimedWithConstTest, TimedShared) {
testTimedShared<TypeParam>();
}
TYPED_TEST(SynchronizedTimedWithConstTest, TimedSynchronizeWithConst) {
testTimedSynchronizedWithConst<TypeParam>();
}
using CountPair = std::pair<int, int>;
// This class is specialized only to be uesed in SynchronizedLockTest
class FakeMutex {
......
......@@ -760,107 +760,6 @@ void testTimedShared() {
<< " timeouts";
}
// Testing the deprecated TIMED_SYNCHRONIZED API
template <class Mutex>
[[deprecated]] void testTimedSynchronized() {
folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<uint64_t, Mutex> numTimeouts{0};
auto worker = [&](size_t threadIdx) {
// Test contextualLock()
v.contextualLock()->push_back(2 * threadIdx);
// Aaand test the TIMED_SYNCHRONIZED macro
for (;;) {
TIMED_SYNCHRONIZED(5, lv, v) {
if (lv) {
// Sleep for a random time to ensure we trigger timeouts
// in other threads
randomSleep(
std::chrono::milliseconds(5), std::chrono::milliseconds(15));
lv->push_back(2 * threadIdx + 1);
return;
}
++(*numTimeouts.contextualLock());
}
}
};
static const size_t numThreads = 100;
runParallel(numThreads, worker);
std::vector<int> result;
v.swap(result);
EXPECT_EQ(2 * numThreads, result.size());
sort(result.begin(), result.end());
for (size_t i = 0; i < 2 * numThreads; ++i) {
EXPECT_EQ(i, result[i]);
}
// We generally expect a large number of number timeouts here.
// I'm not adding a check for it since it's theoretically possible that
// we might get 0 timeouts depending on the CPU scheduling if our threads
// don't get to run very often.
LOG(INFO) << "testTimedSynchronized: " << *numTimeouts.contextualRLock()
<< " timeouts";
}
// Testing the deprecated TIMED_SYNCHRONIZED_CONST API
template <class Mutex>
[[deprecated]] void testTimedSynchronizedWithConst() {
folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<uint64_t, Mutex> numTimeouts{0};
auto worker = [&](size_t threadIdx) {
// Test contextualLock()
v.contextualLock()->push_back(threadIdx);
// Test TIMED_SYNCHRONIZED_CONST
for (;;) {
TIMED_SYNCHRONIZED_CONST(10, lv, v) {
if (lv) {
// Sleep while holding the lock.
//
// This will block other threads from acquiring the write lock to add
// their thread index to v, but it won't block threads that have
// entered the for loop and are trying to acquire a read lock.
//
// For lock types that give preference to readers rather than writers,
// this will tend to serialize all threads on the wlock() above.
randomSleep(
std::chrono::milliseconds(5), std::chrono::milliseconds(15));
auto found = std::find(lv->begin(), lv->end(), threadIdx);
CHECK(found != lv->end());
return;
} else {
++(*numTimeouts.contextualLock());
}
}
}
};
static const size_t numThreads = 100;
runParallel(numThreads, worker);
std::vector<int> result;
v.swap(result);
EXPECT_EQ(numThreads, result.size());
sort(result.begin(), result.end());
for (size_t i = 0; i < numThreads; ++i) {
EXPECT_EQ(i, result[i]);
}
// We generally expect a small number of timeouts here.
// For locks that give readers preference over writers this should usually
// be 0. With locks that give writers preference we do see a small-ish
// number of read timeouts.
LOG(INFO) << "testTimedSynchronizedWithConst: "
<< *numTimeouts.contextualRLock() << " timeouts";
}
template <class Mutex>
void testConstCopy() {
std::vector<int> input = {1, 2, 3};
......
......@@ -51,10 +51,6 @@ void testTimed();
template <class Mutex>
void testTimedShared();
template <class Mutex>
void testTimedSynchronizedDeprecated();
template <class Mutex>
void testTimedSynchronizedWithConst();
template <class Mutex>
void testConstCopy();
template <class Mutex>
void testInPlaceConstruction();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment