Use std::atomic_* overloads for std::shared_ptr if available
This commit is contained in:
parent
db1716ae93
commit
e1dfff8929
20
configure.ac
20
configure.ac
|
@ -234,6 +234,26 @@ std::map<int, int>().emplace(1, 2);
|
|||
[have_std_map_emplace=no
|
||||
AC_MSG_RESULT([no])])
|
||||
|
||||
# Check that std::atomic_* overloads for std::shared_ptr are
|
||||
# available.
|
||||
AC_MSG_CHECKING([whether std::atomic_* overloads for std::shared_ptr are available])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
|
||||
[[
|
||||
#include <memory>
|
||||
]],
|
||||
[[
|
||||
auto a = std::make_shared<int>(1000000007);
|
||||
auto p = std::atomic_load(&a);
|
||||
++*p;
|
||||
std::atomic_store(&a, p);
|
||||
]])],
|
||||
[AC_DEFINE([HAVE_ATOMIC_STD_SHARED_PTR], [1],
|
||||
[Define to 1 if you have the std::atomic_* overloads for std::shared_ptr.])
|
||||
have_atomic_std_shared_ptr=yes
|
||||
AC_MSG_RESULT([yes])],
|
||||
[have_atomic_std_shared_ptr=no
|
||||
AC_MSG_RESULT([no])])
|
||||
|
||||
CXXFLAGS=$save_CXXFLAGS
|
||||
|
||||
AC_LANG_POP()
|
||||
|
|
|
@ -667,9 +667,16 @@ void ConnectionHandler::handle_ocsp_complete() {
|
|||
|
||||
#ifndef OPENSSL_IS_BORINGSSL
|
||||
{
|
||||
#ifdef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::atomic_store_explicit(
|
||||
&tls_ctx_data->ocsp_data,
|
||||
std::make_shared<std::vector<uint8_t>>(std::move(ocsp_.resp)),
|
||||
std::memory_order_release);
|
||||
#else // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::lock_guard<std::mutex> g(tls_ctx_data->mu);
|
||||
tls_ctx_data->ocsp_data =
|
||||
std::make_shared<std::vector<uint8_t>>(std::move(ocsp_.resp));
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
}
|
||||
#else // OPENSSL_IS_BORINGSSL
|
||||
SSL_CTX_set_ocsp_response(ssl_ctx, ocsp_.resp.data(), ocsp_.resp.size());
|
||||
|
|
|
@ -196,8 +196,13 @@ int servername_callback(SSL *ssl, int *al, void *arg) {
|
|||
namespace {
|
||||
std::shared_ptr<std::vector<uint8_t>>
|
||||
get_ocsp_data(TLSContextData *tls_ctx_data) {
|
||||
#ifdef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
return std::atomic_load_explicit(&tls_ctx_data->ocsp_data,
|
||||
std::memory_order_acquire);
|
||||
#else // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::lock_guard<std::mutex> g(tls_ctx_data->mu);
|
||||
return tls_ctx_data->ocsp_data;
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -63,8 +63,10 @@ struct TLSSessionCache {
|
|||
// This struct stores the additional information per SSL_CTX. This is
|
||||
// attached to SSL_CTX using SSL_CTX_set_app_data().
|
||||
struct TLSContextData {
|
||||
#ifndef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
// Protects ocsp_data;
|
||||
std::mutex mu;
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
// OCSP response
|
||||
std::shared_ptr<std::vector<uint8_t>> ocsp_data;
|
||||
|
||||
|
|
|
@ -415,13 +415,23 @@ void Worker::process_events() {
|
|||
ssl::CertLookupTree *Worker::get_cert_lookup_tree() const { return cert_tree_; }
|
||||
|
||||
std::shared_ptr<TicketKeys> Worker::get_ticket_keys() {
|
||||
std::lock_guard<std::mutex> g(m_);
|
||||
#ifdef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
return std::atomic_load_explicit(&ticket_keys_, std::memory_order_acquire);
|
||||
#else // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::lock_guard<std::mutex> g(ticket_keys_m_);
|
||||
return ticket_keys_;
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
}
|
||||
|
||||
void Worker::set_ticket_keys(std::shared_ptr<TicketKeys> ticket_keys) {
|
||||
std::lock_guard<std::mutex> g(m_);
|
||||
#ifdef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
// This is single writer
|
||||
std::atomic_store_explicit(&ticket_keys_, std::move(ticket_keys),
|
||||
std::memory_order_release);
|
||||
#else // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::lock_guard<std::mutex> g(ticket_keys_m_);
|
||||
ticket_keys_ = std::move(ticket_keys);
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
}
|
||||
|
||||
WorkerStat *Worker::get_worker_stat() { return &worker_stat_; }
|
||||
|
|
|
@ -274,6 +274,9 @@ private:
|
|||
ssl::CertLookupTree *cert_tree_;
|
||||
ConnectionHandler *conn_handler_;
|
||||
|
||||
#ifndef HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::mutex ticket_keys_m_;
|
||||
#endif // !HAVE_ATOMIC_STD_SHARED_PTR
|
||||
std::shared_ptr<TicketKeys> ticket_keys_;
|
||||
std::vector<std::shared_ptr<DownstreamAddrGroup>> downstream_addr_groups_;
|
||||
// Worker level blocker for downstream connection. For example,
|
||||
|
|
Loading…
Reference in New Issue