/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <folly/synchronization/AsymmetricThreadFence.h> #include <mutex> #include <folly/Exception.h> #include <folly/Indestructible.h> #include <folly/portability/SysMembarrier.h> #include <folly/portability/SysMman.h> #include <folly/synchronization/RelaxedAtomic.h> namespace folly { namespace { // The intention is to force a memory barrier in every core running any of the // process's threads. There is not a wide selection of options, but we do have // one trick: force a TLB shootdown. There are multiple scenarios in which a TLB // shootdown occurs, two of which are relevant: (1) when a resident page is // swapped out, and (2) when the protection on a resident page is downgraded. // We cannot force (1) and we cannot force (2). But we can force at least one of // the outcomes (1) or (2) to happen! void mprotectMembarrier() { … } bool sysMembarrierAvailableCached() { … } } // namespace void asymmetric_thread_fence_heavy_fn::impl_(std::memory_order order) noexcept { … } } // namespace folly