userver: userver/concurrent/impl/asymmetric_fence.hpp Source File
Loading...
Searching...
No Matches
asymmetric_fence.hpp
1#pragma once
2
3USERVER_NAMESPACE_BEGIN
4
5namespace concurrent::impl {
6
7// A pair of AsymmetricThreadFenceLight + AsymmetricThreadFenceHeavy
8// synchronizes like std::atomic_thread_fence(std::memory_order_seq_cst)
9//
10// Light version is very fast (~1ns) and Heavy version is quite slow
11// (1 context switch per CPU core ~1us).
12//
13// Supported systems: x86_64 Linux with kernel version 4.14+.
14// On other systems, these are implemented as
15// std::atomic_thread_fence(std::memory_order_seq_cst).
16//
17// See:
18// https://man.archlinux.org/man/membarrier.2.ru
19// https://wg21.link/p1202
20// https://github.com/facebook/folly/blob/main/folly/synchronization/AsymmetricThreadFence.cpp
21void AsymmetricThreadFenceLight() noexcept;
22void AsymmetricThreadFenceHeavy() noexcept;
23
24// Automatic thread registration for asymmetric thread fences uses
25// an unprotected thread_local access. On thread pools of thread-migrating
26// coroutines, this should be called before any AsymmetricThreadFence* calls.
27void AsymmetricThreadFenceForceRegisterThread() noexcept;
28
29} // namespace concurrent::impl
30
31USERVER_NAMESPACE_END