![]() |
MySQL 26.10.0
Source Code Documentation
|
Registry of per-thread values owned by one enclosing object. More...
#include <ut0per_thread.h>
Public Member Functions | |
| Per_thread (std::function< Value()> factory) | |
| Create an empty registry. More... | |
| Per_thread (const Per_thread &)=delete | |
| Per_thread & | operator= (const Per_thread &)=delete |
| Value * | operator-> () |
| Return this thread's Value, creating and storing it on first access. More... | |
Private Attributes | |
| std::function< Value()> | m_factory |
| std::mutex | m_mutex |
| std::unordered_map< std::thread::id, Value > | m_map |
Registry of per-thread values owned by one enclosing object.
This solves the case in which code needs one Value per participating thread, but the values must follow the lifetime of a registry. Plain thread_local is not enough, because thread-local objects outlive the registry and are destroyed only when their threads exit.
|
inlineexplicit |
Create an empty registry.
| [in] | factory | callable used to create the current thread's Value on the first access from that thread; must be non-empty; must not attempt calling the Per_thread::operator->() as it could lead to endless recursion. |
|
delete |
|
inline |
Return this thread's Value, creating and storing it on first access.
Repeated calls from the same thread return the same object until the registry is destroyed.
As thread ids might be reused, it is possible that a new thread "inherits" the Value which was used by an old thread, instead of starting with a fresh one.
|
delete |
|
private |
|
private |
|
private |