proxygen
folly::ssl::detail Namespace Reference

Classes

class  SSLSessionImpl
 

Functions

static std::map< int, LockType > & lockTypes ()
 
void setLockTypes (std::map< int, LockType > inLockTypes)
 
bool isSSLLockDisabled (int lockId)
 
static std::unique_ptr< SSLLock[]> & locks ()
 
static void callbackLocking (int mode, int n, const char *, int)
 
static unsigned long callbackThreadID ()
 
static CRYPTO_dynlock_valuedyn_create (const char *, int)
 
static void dyn_lock (int mode, struct CRYPTO_dynlock_value *lock, const char *, int)
 
static void dyn_destroy (struct CRYPTO_dynlock_value *lock, const char *, int)
 
void installThreadingLocks ()
 
void cleanupThreadingLocks ()
 

Function Documentation

static void folly::ssl::detail::callbackLocking ( int  mode,
int  n,
const char *  ,
int   
)
static

Definition at line 123 of file OpenSSLThreading.cpp.

References locks().

Referenced by installThreadingLocks().

123  {
124  if (mode & CRYPTO_LOCK) {
125  locks()[size_t(n)].lock(mode & CRYPTO_READ);
126  } else {
127  locks()[size_t(n)].unlock(mode & CRYPTO_READ);
128  }
129 }
static std::unique_ptr< SSLLock[]> & locks()
folly::Optional< PskKeyExchangeMode > mode
static unsigned long folly::ssl::detail::callbackThreadID ( )
static

Definition at line 131 of file OpenSSLThreading.cpp.

References folly::getCurrentThreadID().

Referenced by installThreadingLocks().

131  {
132  return static_cast<unsigned long>(folly::getCurrentThreadID());
133 }
uint64_t getCurrentThreadID()
Definition: ThreadId.h:42
void folly::ssl::detail::cleanupThreadingLocks ( )

Definition at line 168 of file OpenSSLThreading.cpp.

References locks().

Referenced by folly::portability::ssl::OPENSSL_cleanup().

168  {
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);
174  locks().reset();
175 }
static std::unique_ptr< SSLLock[]> & locks()
static CRYPTO_dynlock_value* folly::ssl::detail::dyn_create ( const char *  ,
int   
)
static

Definition at line 135 of file OpenSSLThreading.cpp.

Referenced by installThreadingLocks().

135  {
136  return new CRYPTO_dynlock_value;
137 }
static void folly::ssl::detail::dyn_destroy ( struct CRYPTO_dynlock_value lock,
const char *  ,
int   
)
static

Definition at line 150 of file OpenSSLThreading.cpp.

References folly::detail::lock().

Referenced by installThreadingLocks().

150  {
151  delete lock;
152 }
auto lock(SynchronizedLocker...lockersIn) -> std::tuple< typename SynchronizedLocker::LockedPtr... >
Definition: Synchronized.h:871
static void folly::ssl::detail::dyn_lock ( int  mode,
struct CRYPTO_dynlock_value lock,
const char *  ,
int   
)
static

Definition at line 140 of file OpenSSLThreading.cpp.

References CRYPTO_dynlock_value::mutex.

Referenced by installThreadingLocks().

140  {
141  if (lock != nullptr) {
142  if (mode & CRYPTO_LOCK) {
143  lock->mutex.lock();
144  } else {
145  lock->mutex.unlock();
146  }
147  }
148 }
folly::Optional< PskKeyExchangeMode > mode
void folly::ssl::detail::installThreadingLocks ( )

Definition at line 154 of file OpenSSLThreading.cpp.

References callbackLocking(), callbackThreadID(), dyn_create(), dyn_destroy(), dyn_lock(), locks(), and lockTypes().

Referenced by folly::portability::ssl::OPENSSL_init_ssl().

154  {
155  // static locking
156  locks() = std::make_unique<SSLLock[]>(size_t(CRYPTO_num_locks()));
157  for (auto it : lockTypes()) {
158  locks()[size_t(it.first)].lockType = it.second;
159  }
160  CRYPTO_set_id_callback(callbackThreadID);
161  CRYPTO_set_locking_callback(callbackLocking);
162  // dynamic locking
163  CRYPTO_set_dynlock_create_callback(dyn_create);
164  CRYPTO_set_dynlock_lock_callback(dyn_lock);
165  CRYPTO_set_dynlock_destroy_callback(dyn_destroy);
166 }
static CRYPTO_dynlock_value * dyn_create(const char *, int)
static std::unique_ptr< SSLLock[]> & locks()
static std::map< int, LockType > & lockTypes()
static void dyn_destroy(struct CRYPTO_dynlock_value *lock, const char *, int)
static unsigned long callbackThreadID()
static void callbackLocking(int mode, int n, const char *, int)
static void dyn_lock(int mode, struct CRYPTO_dynlock_value *lock, const char *, int)
bool folly::ssl::detail::isSSLLockDisabled ( int  lockId)

Definition at line 64 of file OpenSSLThreading.cpp.

References folly::SpinLock::lock(), folly::detail::lock(), lockType, lockTypes(), CRYPTO_dynlock_value::mutex, fizz::detail::read(), sharedMutex, spinLock, and folly::SpinLock::unlock().

Referenced by folly::ssl::isLockDisabled().

64  {
65  const auto& sslLocks = lockTypes();
66  const auto it = sslLocks.find(lockId);
67  return it != sslLocks.end() && it->second == LockType::NONE;
68 }
static std::map< int, LockType > & lockTypes()
static std::unique_ptr<SSLLock[]>& folly::ssl::detail::locks ( )
static

Definition at line 118 of file OpenSSLThreading.cpp.

Referenced by callbackLocking(), cleanupThreadingLocks(), installThreadingLocks(), folly::lock(), runContended(), runFairness(), runPingPong(), and folly::TEST().

118  {
119  static auto locksInst = new std::unique_ptr<SSLLock[]>();
120  return *locksInst;
121 }
static std::map<int, LockType>& folly::ssl::detail::lockTypes ( )
static

Definition at line 50 of file OpenSSLThreading.cpp.

Referenced by installThreadingLocks(), isSSLLockDisabled(), and setLockTypes().

50  {
51  static auto lockTypesInst = new std::map<int, LockType>();
52  return *lockTypesInst;
53 }
void folly::ssl::detail::setLockTypes ( std::map< int, LockType inLockTypes)

Definition at line 55 of file OpenSSLThreading.cpp.

References folly::INFO, and lockTypes().

Referenced by folly::ssl::setLockTypes(), and folly::ssl::setLockTypesAndInit().

55  {
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";
59 #endif
60 
61  lockTypes() = inLockTypes;
62 }
static std::map< int, LockType > & lockTypes()