Commit 4037ae31 authored by Aaryaman Sagar's avatar Aaryaman Sagar Committed by Facebook Github Bot

Remove some unused code from LockTraits

Summary:
There was some code that optionally acquired a lock in a shared or exclusive
manner based on whether those methods were available for the mutex or not.
This was not used anywhere

Reviewed By: yfeldblum

Differential Revision: D7722906

fbshipit-source-id: b749527c13a1d980134cc23dea586c83a0b65e91
parent f9cf216a
......@@ -414,57 +414,6 @@ struct LockTraitsBase
template <class Mutex>
struct LockTraits : public LockTraitsBase<Mutex> {};
/**
* If the lock is a shared lock, acquire it in shared mode.
* Otherwise, for plain (exclusive-only) locks, perform a normal acquire.
*/
template <class Mutex>
typename std::enable_if<LockTraits<Mutex>::is_shared>::type
lock_shared_or_unique(Mutex& mutex) {
LockTraits<Mutex>::lock_shared(mutex);
}
template <class Mutex>
typename std::enable_if<!LockTraits<Mutex>::is_shared>::type
lock_shared_or_unique(Mutex& mutex) {
LockTraits<Mutex>::lock(mutex);
}
/**
* If the lock is a shared lock, try to acquire it in shared mode, for up to
* the given timeout. Otherwise, for plain (exclusive-only) locks, try to
* perform a normal acquire.
*
* Returns true if the lock was acquired, or false on time out.
*/
template <class Mutex, class Rep, class Period>
typename std::enable_if<LockTraits<Mutex>::is_shared, bool>::type
try_lock_shared_or_unique_for(
Mutex& mutex,
const std::chrono::duration<Rep, Period>& timeout) {
return LockTraits<Mutex>::try_lock_shared_for(mutex, timeout);
}
template <class Mutex, class Rep, class Period>
typename std::enable_if<!LockTraits<Mutex>::is_shared, bool>::type
try_lock_shared_or_unique_for(
Mutex& mutex,
const std::chrono::duration<Rep, Period>& timeout) {
return LockTraits<Mutex>::try_lock_for(mutex, timeout);
}
/**
* Release a lock acquired with lock_shared_or_unique()
*/
template <class Mutex>
typename std::enable_if<LockTraits<Mutex>::is_shared>::type
unlock_shared_or_unique(Mutex& mutex) {
LockTraits<Mutex>::unlock_shared(mutex);
}
template <class Mutex>
typename std::enable_if<!LockTraits<Mutex>::is_shared>::type
unlock_shared_or_unique(Mutex& mutex) {
LockTraits<Mutex>::unlock(mutex);
}
/*
* Lock policy classes.
*
......@@ -515,28 +464,6 @@ struct LockPolicyShared {
}
};
/**
* A lock policy that performs a shared lock operation if a shared mutex type
* is given, or a normal exclusive lock operation on non-shared mutex types.
*/
struct LockPolicyShareable {
template <class Mutex>
static std::true_type lock(Mutex& mutex) {
lock_shared_or_unique(mutex);
return std::true_type{};
}
template <class Mutex, class Rep, class Period>
static bool try_lock_for(
Mutex& mutex,
const std::chrono::duration<Rep, Period>& timeout) {
return try_lock_shared_or_unique_for(mutex, timeout);
}
template <class Mutex>
static void unlock(Mutex& mutex) {
unlock_shared_or_unique(mutex);
}
};
/**
* A lock policy with the following mapping
*
......
......@@ -113,9 +113,6 @@ TEST(LockTraits, std_mutex) {
std::mutex mutex;
traits::lock(mutex);
traits::unlock(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, SharedMutex) {
......@@ -133,11 +130,6 @@ TEST(LockTraits, SharedMutex) {
traits::unlock_shared(mutex);
traits::unlock_shared(mutex);
lock_shared_or_unique(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
traits::lock_upgrade(mutex);
traits::unlock_upgrade(mutex);
......@@ -197,9 +189,6 @@ TEST(LockTraits, SpinLock) {
SpinLock mutex;
traits::lock(mutex);
traits::unlock(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, RWSpinLock) {
......@@ -216,11 +205,6 @@ TEST(LockTraits, RWSpinLock) {
traits::lock_shared(mutex);
traits::unlock_shared(mutex);
traits::unlock_shared(mutex);
lock_shared_or_unique(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, boost_mutex) {
......@@ -232,9 +216,6 @@ TEST(LockTraits, boost_mutex) {
boost::mutex mutex;
traits::lock(mutex);
traits::unlock(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, boost_recursive_mutex) {
......@@ -251,11 +232,6 @@ TEST(LockTraits, boost_recursive_mutex) {
traits::lock(mutex);
traits::unlock(mutex);
traits::unlock(mutex);
lock_shared_or_unique(mutex);
lock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
#if FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES
......@@ -272,12 +248,6 @@ TEST(LockTraits, timed_mutex) {
EXPECT_FALSE(gotLock) << "should not have been able to acquire the "
<< "timed_mutex a second time";
traits::unlock(mutex);
lock_shared_or_unique(mutex);
gotLock = try_lock_shared_or_unique_for(mutex, std::chrono::milliseconds(1));
EXPECT_FALSE(gotLock) << "should not have been able to acquire the "
<< "timed_mutex a second time";
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, recursive_timed_mutex) {
......@@ -296,13 +266,6 @@ TEST(LockTraits, recursive_timed_mutex) {
<< "recursive_timed_mutex a second time";
traits::unlock(mutex);
traits::unlock(mutex);
lock_shared_or_unique(mutex);
gotLock = try_lock_shared_or_unique_for(mutex, std::chrono::milliseconds(10));
EXPECT_TRUE(gotLock) << "should have been able to acquire the "
<< "recursive_timed_mutex a second time";
unlock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
TEST(LockTraits, boost_shared_mutex) {
......@@ -331,16 +294,6 @@ TEST(LockTraits, boost_shared_mutex) {
<< "shared_mutex a second time in shared mode";
traits::unlock_shared(mutex);
traits::unlock_shared(mutex);
lock_shared_or_unique(mutex);
gotLock = traits::try_lock_for(mutex, std::chrono::milliseconds(1));
EXPECT_FALSE(gotLock) << "should not have been able to acquire the "
<< "shared_mutex a second time";
gotLock = try_lock_shared_or_unique_for(mutex, std::chrono::milliseconds(10));
EXPECT_TRUE(gotLock) << "should have been able to acquire the "
<< "shared_mutex a second time in shared mode";
unlock_shared_or_unique(mutex);
unlock_shared_or_unique(mutex);
}
#endif // FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES
......
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