#pragma once #include // M10.9d (ADR-0097): Mbed TLS and PSA are built without MBEDTLS_THREADING_C, so their // global state (the PSA core, key slots, the random generator) is not safe to use from // several threads at once. Every network-library entry point that touches them takes this // one process-wide lock: the QUIC client's pinned certificate check and the session grant // and handoff ticket keys. Recursive, since entry points may call each other. Calls are rare // (per connection, per grant), so the lock costs nothing measurable. Found by evo-load: two // bots on different threads verifying their first connections at once were refused as // `untrusted`. namespace evo::network { inline std::recursive_mutex& crypto_mutex() noexcept { static std::recursive_mutex mutex; return mutex; } using CryptoLock = std::scoped_lock; } // namespace evo::network