X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FLockTraits.h;h=c780ce8d05636a9127235744e89352a9da98909a;hb=b50a3dd838801676f9f5a3d5f0b9a094a8175d72;hp=15ffe1124079c26a16b3f31fd3bc234bad7292a7;hpb=7dd2b5809516d608c4c8f7da7ee3a8f517440003;p=folly.git diff --git a/folly/LockTraits.h b/folly/LockTraits.h index 15ffe112..c780ce8d 100644 --- a/folly/LockTraits.h +++ b/folly/LockTraits.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2016-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,8 @@ #include #include +#include + // Android, OSX, and Cygwin don't have timed mutexes #if defined(ANDROID) || defined(__ANDROID__) || defined(__APPLE__) || \ defined(__CYGWIN__) @@ -38,6 +40,13 @@ namespace folly { namespace detail { +namespace member { +FOLLY_CREATE_MEMBER_INVOKE_TRAITS(lock, lock); +FOLLY_CREATE_MEMBER_INVOKE_TRAITS(try_lock_for, try_lock_for); +FOLLY_CREATE_MEMBER_INVOKE_TRAITS(lock_shared, lock_shared); +FOLLY_CREATE_MEMBER_INVOKE_TRAITS(lock_upgrade, lock_upgrade); +} // namespace member + /** * An enum to describe the "level" of a mutex. The supported levels are * Unique - a normal mutex that supports only exclusive locking @@ -71,46 +80,25 @@ struct MutexLevelValueImpl { * mutex. This is used in conjunction with the above MutexLevel * specializations and the LockTraitsImpl to determine what functions are * supported by objects of type Mutex - * - * The implementation uses SINAE in the return value with trailing return - * types to figure out what level a mutex is */ template class LockInterfaceDispatcher { private: // assert that the mutex type has basic lock and unlock functions static_assert( - std::is_same().lock()), void>::value, + member::lock::is_invocable::value, "The mutex type must support lock and unlock functions"); - // Helper functions for implementing the traits using SFINAE - template - static auto timed_lock_test(T*) -> typename std::is_same< - decltype(std::declval().try_lock_for(std::chrono::milliseconds(0))), - bool>::type; - template - static std::false_type timed_lock_test(...); - - template - static auto lock_shared_test(T*) -> typename std:: - is_same().lock_shared()), void>::type; - template - static std::false_type lock_shared_test(...); - - template - static auto lock_upgrade_test(T*) -> typename std:: - is_same().lock_upgrade()), void>::type; - template - static std::false_type lock_upgrade_test(...); + using duration = std::chrono::milliseconds; public: static constexpr bool has_lock_unique = true; static constexpr bool has_lock_timed = - decltype(timed_lock_test(0))::value; + member::try_lock_for::is_invocable::value; static constexpr bool has_lock_shared = - decltype(lock_shared_test(0))::value; + member::lock_shared::is_invocable::value; static constexpr bool has_lock_upgrade = - decltype(lock_upgrade_test(0))::value; + member::lock_upgrade::is_invocable::value; }; /** @@ -338,7 +326,7 @@ struct LockTraitsImpl } }; -} // detail +} // namespace detail /** * LockTraits describes details about a particular mutex type. @@ -637,4 +625,4 @@ struct LockPolicyFromExclusiveToShared : public LockPolicyShared { } }; -} // folly +} // namespace folly