MySQL 8.4.0
Source Code Documentation
temptable::Lock_free_type_selector< T, V > Struct Template Reference

Lock-free type selector, a helper utility which evaluates during the compile-time whether the given type T has a property of being always-lock-free for given platform. More...

#include <lock_free_type.h>

Detailed Description

template<typename T, typename V = void>
struct temptable::Lock_free_type_selector< T, V >

Lock-free type selector, a helper utility which evaluates during the compile-time whether the given type T has a property of being always-lock-free for given platform.

If true, Lock_free_type_selector::Type will hold T, otherwise Lock_free_type_selector::Type will be inexisting in which case static-assert will be triggered with a hopefully descriptive error-message. In the event of static-assert, one can either try to select another type T or, if one does not care about the actual underlying type representation, simply utilize the Largest_lock_free_type_selector utility instead. This utility will work out those details automagically. For more information, see documentation on Largest_lock_free_type_selector.

In short, reasoning behind this machinery lies in the fact that the standard cannot guarantee that underlying implementation of std::atomic<T> is going to be able to use lock-free atomic CPU instructions. That obviously depends on the given type T but also on the properties of concrete platform. Therefore, actual implementation is mostly platform-dependent and is free to choose any other locking operation (e.g. mutex) as long as it is able to fulfill the atomicity. Lock-freedom is not a pre-requisite. Only exception is std::atomic_flag.

For certain types, however, lock-freedom can be claimed upfront during the compile-time phase, and this is where this utiliy kicks in. It is essentially a C++14 rewrite of std::atomic<T>::is_always_lock_free which is only available from C++17 onwards. Once moved to C++17 this utility will become obsolete and shall be replaced with standard-compliant implementation.

More details and motivation can be found at: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0152r0.html


The documentation for this struct was generated from the following file: