MySQL 9.0.0
Source Code Documentation
ut_lock_free_list_node_t< T > Class Template Reference

A node in a linked list of arrays. More...

#include <ut0lock_free_hash.h>

Public Types

typedef ut_lock_free_list_node_t< T > * next_t
 

Public Member Functions

 ut_lock_free_list_node_t (size_t n_elements)
 Constructor. More...
 
next_t grow (int64_t deleted_val, bool *grown_by_this_thread)
 Create and append a new array to this one and store a pointer to it in 'm_next'. More...
 
ut_lock_free_cnt_t::handle_t begin_access ()
 Mark the beginning of an access to this object. More...
 
void await_release_of_old_references ()
 Wait until all previously held references are released. More...
 

Static Public Member Functions

static ut_lock_free_list_node_talloc (size_t n_elements)
 
static void dealloc (ut_lock_free_list_node_t *ptr)
 

Public Attributes

ut::unique_ptr< T[]> m_base
 Base array. More...
 
size_t m_n_base_elements
 Number of elements in 'm_base'. More...
 
std::atomic_bool m_pending_free
 Indicate whether some thread is waiting for readers to go away before it can free the memory occupied by the m_base member. More...
 
std::atomic< next_tm_next
 Pointer to the next node if any or NULL. More...
 

Private Member Functions

size_t n_deleted (int64_t deleted_val) const
 Count the number of deleted elements. More...
 

Private Attributes

ut_lock_free_cnt_t m_n_ref
 Counter for the current number of readers and writers to this object. More...
 

Detailed Description

template<typename T>
class ut_lock_free_list_node_t< T >

A node in a linked list of arrays.

The pointer to the next node is atomically set (CAS) when a next element is allocated.

Member Typedef Documentation

◆ next_t

template<typename T >
typedef ut_lock_free_list_node_t<T>* ut_lock_free_list_node_t< T >::next_t

Constructor & Destructor Documentation

◆ ut_lock_free_list_node_t()

template<typename T >
ut_lock_free_list_node_t< T >::ut_lock_free_list_node_t ( size_t  n_elements)
inlineexplicit

Constructor.

Parameters
[in]n_elementsnumber of elements to create

Member Function Documentation

◆ alloc()

template<typename T >
static ut_lock_free_list_node_t * ut_lock_free_list_node_t< T >::alloc ( size_t  n_elements)
inlinestatic

◆ await_release_of_old_references()

template<typename T >
void ut_lock_free_list_node_t< T >::await_release_of_old_references ( )
inline

Wait until all previously held references are released.

◆ begin_access()

template<typename T >
ut_lock_free_cnt_t::handle_t ut_lock_free_list_node_t< T >::begin_access ( )
inline

Mark the beginning of an access to this object.

Used to prevent a destruction of an array pointed by m_base while our thread is accessing it.

Returns
A handle which protects the m_base as long as the handle is not destructed. If the handle is {} (==false), the access was denied, this object is to be removed from the list and thus new access to it is not allowed. The caller should retry from the head of the list.

◆ dealloc()

template<typename T >
static void ut_lock_free_list_node_t< T >::dealloc ( ut_lock_free_list_node_t< T > *  ptr)
inlinestatic

◆ grow()

template<typename T >
next_t ut_lock_free_list_node_t< T >::grow ( int64_t  deleted_val,
bool *  grown_by_this_thread 
)
inline

Create and append a new array to this one and store a pointer to it in 'm_next'.

This is done in a way that multiple threads can attempt this at the same time and only one will succeed. When this method returns, the caller can be sure that the job is done (either by this or another thread).

Parameters
[in]deleted_valthe constant that designates that a value is deleted
[out]grown_by_this_threadset to true if the next array was created and appended by this thread; set to false if created and appended by another thread.
Returns
the next array, appended by this or another thread

◆ n_deleted()

template<typename T >
size_t ut_lock_free_list_node_t< T >::n_deleted ( int64_t  deleted_val) const
inlineprivate

Count the number of deleted elements.

The value returned could be inaccurate because it is obtained without any locks.

Parameters
[in]deleted_valthe constant that designates that a value is deleted
Returns
the number of deleted elements

Member Data Documentation

◆ m_base

template<typename T >
ut::unique_ptr<T[]> ut_lock_free_list_node_t< T >::m_base

Base array.

◆ m_n_base_elements

template<typename T >
size_t ut_lock_free_list_node_t< T >::m_n_base_elements

Number of elements in 'm_base'.

◆ m_n_ref

template<typename T >
ut_lock_free_cnt_t ut_lock_free_list_node_t< T >::m_n_ref
private

Counter for the current number of readers and writers to this object.

This object is destroyed only after it is removed from the list, so that no new readers or writers may arrive, and after this counter has dropped to zero.

◆ m_next

template<typename T >
std::atomic<next_t> ut_lock_free_list_node_t< T >::m_next

Pointer to the next node if any or NULL.

This begins its life as NULL and is only changed once to some real value. Never changed to another value after that.

◆ m_pending_free

template<typename T >
std::atomic_bool ut_lock_free_list_node_t< T >::m_pending_free

Indicate whether some thread is waiting for readers to go away before it can free the memory occupied by the m_base member.


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