26 #include <glog/logging.h> 32 #include <openssl/crypto.h> 34 #if !defined(OPENSSL_IS_BORINGSSL) 35 #define FOLLY_SSL_DETAIL_OPENSSL_IS_110 (OPENSSL_VERSION_NUMBER >= 0x10100000L) 37 #define FOLLY_SSL_DETAIL_OPENSSL_IS_110 (false) 51 static auto lockTypesInst =
new std::map<int, LockType>();
52 return *lockTypesInst;
56 #if FOLLY_SSL_DETAIL_OPENSSL_IS_110 57 LOG(
INFO) <<
"setLockTypes() is unsupported on OpenSSL >= 1.1.0. " 58 <<
"OpenSSL now uses platform native mutexes";
66 const auto it = sslLocks.find(lockId);
67 return it != sslLocks.end() && it->second == LockType::NONE;
72 explicit SSLLock(
LockType inLockType = LockType::MUTEX)
78 }
else if (
lockType == LockType::SPINLOCK) {
80 }
else if (
lockType == LockType::SHAREDMUTEX) {
90 void unlock(
bool read) {
93 }
else if (
lockType == LockType::SPINLOCK) {
95 }
else if (
lockType == LockType::SHAREDMUTEX) {
118 static std::unique_ptr<SSLLock[]>&
locks() {
119 static auto locksInst =
new std::unique_ptr<SSLLock[]>();
124 if (mode & CRYPTO_LOCK) {
125 locks()[size_t(n)].lock(mode & CRYPTO_READ);
127 locks()[size_t(n)].unlock(mode & CRYPTO_READ);
141 if (lock !=
nullptr) {
142 if (mode & CRYPTO_LOCK) {
145 lock->
mutex.unlock();
156 locks() = std::make_unique<SSLLock[]>(size_t(CRYPTO_num_locks()));
158 locks()[size_t(it.first)].lockType = it.second;
163 CRYPTO_set_dynlock_create_callback(
dyn_create);
164 CRYPTO_set_dynlock_lock_callback(
dyn_lock);
169 CRYPTO_set_id_callback(
nullptr);
170 CRYPTO_set_locking_callback(
nullptr);
171 CRYPTO_set_dynlock_create_callback(
nullptr);
172 CRYPTO_set_dynlock_lock_callback(
nullptr);
173 CRYPTO_set_dynlock_destroy_callback(
nullptr);
static CRYPTO_dynlock_value * dyn_create(const char *, int)
static std::unique_ptr< SSLLock[]> & locks()
void cleanupThreadingLocks()
static std::map< int, LockType > & lockTypes()
static void dyn_destroy(struct CRYPTO_dynlock_value *lock, const char *, int)
—— Concurrent Priority Queue Implementation ——
FOLLY_ALWAYS_INLINE void unlock() const noexcept
void installThreadingLocks()
folly::Optional< PskKeyExchangeMode > mode
static unsigned long callbackThreadID()
auto lock(SynchronizedLocker...lockersIn) -> std::tuple< typename SynchronizedLocker::LockedPtr... >
size_t read(T &out, folly::io::Cursor &cursor)
SharedMutexWritePriority SharedMutex
FOLLY_ALWAYS_INLINE void lock() const noexcept
static void callbackLocking(int mode, int n, const char *, int)
void setLockTypes(std::map< int, LockType > inLockTypes)
uint64_t getCurrentThreadID()
static void dyn_lock(int mode, struct CRYPTO_dynlock_value *lock, const char *, int)
bool isSSLLockDisabled(int lockId)