/* * 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. */ #pragma once #include <atomic> #include <folly/Portability.h> namespace folly { // Valid status values returned from rtmBegin. // kRtmDisabled is a new return value indicating that RTM support is unavailable // on the platform or the compiler. constexpr unsigned kRtmDisabled = …; constexpr unsigned kRtmBeginStarted = …; // Valid abort status bits (when the status value is not kRtmBeginStarted or // kRtmDisabled), defined as per the Intel RTM specifications: // https://en.wikipedia.org/wiki/Transactional_Synchronization_Extensions. constexpr unsigned kRtmAbortExplicit = …; constexpr unsigned kRtmAbortRetry = …; constexpr unsigned kRtmAbortConflict = …; constexpr unsigned kRtmAbortCapacity = …; constexpr unsigned kRtmAbortDebug = …; constexpr unsigned kRtmAbortNested = …; // False if there is no need for a dynamic check to see if // the current environment supports RTM constexpr bool kRtmSupportEnabled = …; // Check on cpu support for tsx-rtm extern bool rtmEnabled(); namespace detail { // Use func ptrs to access the txn functions to avoid txn aborts // due to plt mapping. extern std::atomic<unsigned (*)()> rtmBeginV; extern std::atomic<void (*)()> rtmEndV; extern std::atomic<bool (*)()> rtmTestV; extern std::atomic<void (*)(uint8_t)> rtmAbortV; } // namespace detail inline unsigned rtmBegin() { … } inline void rtmEnd() { … } inline bool rtmTest() { … } inline void rtmAbort(uint8_t status) { … } inline uint8_t rtmStatusToAbortCode(unsigned status) { … } } // namespace folly