summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b3e1ea3)
#include <folly/Format.h>
#include <folly/Memory.h>
#include <folly/Random.h>
#include <folly/Format.h>
#include <folly/Memory.h>
#include <folly/Random.h>
+#include <folly/SharedMutex.h>
#include <folly/SpinLock.h>
#include <folly/ThreadId.h>
#include <folly/SpinLock.h>
#include <folly/ThreadId.h>
if (lockType == SSLContext::LOCK_MUTEX) {
mutex.lock();
} else if (lockType == SSLContext::LOCK_SPINLOCK) {
spinLock.lock();
if (lockType == SSLContext::LOCK_MUTEX) {
mutex.lock();
} else if (lockType == SSLContext::LOCK_SPINLOCK) {
spinLock.lock();
+ } else if (lockType == SSLContext::LOCK_SHAREDMUTEX) {
+ if (read) {
+ sharedMutex.lock_shared();
+ } else {
+ sharedMutex.lock();
+ }
}
// lockType == LOCK_NONE, no-op
}
}
// lockType == LOCK_NONE, no-op
}
+ void unlock(bool read) {
if (lockType == SSLContext::LOCK_MUTEX) {
mutex.unlock();
} else if (lockType == SSLContext::LOCK_SPINLOCK) {
spinLock.unlock();
if (lockType == SSLContext::LOCK_MUTEX) {
mutex.unlock();
} else if (lockType == SSLContext::LOCK_SPINLOCK) {
spinLock.unlock();
+ } else if (lockType == SSLContext::LOCK_SHAREDMUTEX) {
+ if (read) {
+ sharedMutex.unlock_shared();
+ } else {
+ sharedMutex.unlock();
+ }
}
// lockType == LOCK_NONE, no-op
}
}
// lockType == LOCK_NONE, no-op
}
SSLContext::SSLLockType lockType;
folly::SpinLock spinLock{};
std::mutex mutex;
SSLContext::SSLLockType lockType;
folly::SpinLock spinLock{};
std::mutex mutex;
+ SharedMutex sharedMutex;
};
// Statics are unsafe in environments that call exit().
};
// Statics are unsafe in environments that call exit().
static void callbackLocking(int mode, int n, const char*, int) {
if (mode & CRYPTO_LOCK) {
static void callbackLocking(int mode, int n, const char*, int) {
if (mode & CRYPTO_LOCK) {
- locks()[size_t(n)].lock();
+ locks()[size_t(n)].lock(mode & CRYPTO_READ);
- locks()[size_t(n)].unlock();
+ locks()[size_t(n)].unlock(mode & CRYPTO_READ);
- enum SSLLockType {
- LOCK_MUTEX,
- LOCK_SPINLOCK,
- LOCK_NONE
- };
+ enum SSLLockType { LOCK_MUTEX, LOCK_SPINLOCK, LOCK_SHAREDMUTEX, LOCK_NONE };
/**
* Set preferences for how to treat locks in OpenSSL. This must be
/**
* Set preferences for how to treat locks in OpenSSL. This must be