MySQL 8.4.3
Source Code Documentation
lf.h File Reference
#include "my_config.h"
#include <stddef.h>
#include <sys/types.h>
#include <atomic>
#include "my_inttypes.h"
#include "my_macros.h"
#include "mysql/psi/mysql_statement.h"
#include "mysql/service_mysql_alloc.h"
#include "sql_string.h"

Go to the source code of this file.

Classes

struct  LF_DYNARRAY
 
struct  LF_PINBOX
 
struct  LF_PINS
 
struct  LF_ALLOCATOR
 
struct  LF_HASH
 

Macros

#define LF_DYNARRAY_LEVEL_LENGTH   256
 
#define LF_DYNARRAY_LEVELS   4
 
#define LF_PINBOX_PINS   4
 
#define LF_PURGATORY_SIZE   10
 
#define LF_REQUIRE_PINS(N)
 
#define lf_alloc_init(A, B, C)   lf_alloc_init2(A, B, C, NULL, NULL)
 
#define LF_HASH_UNIQUE   1
 
#define MY_LF_ERRPTR   ((void *)(intptr)1)
 
#define lf_hash_init(A, B, C, D, E, F, G)    lf_hash_init2(A, B, C, D, E, F, G, NULL, NULL, NULL, NULL)
 

Typedefs

typedef int(* lf_dynarray_func) (void *, void *)
 
typedef void lf_pinbox_free_func(void *, void *, void *)
 
typedef void lf_allocator_func(uchar *)
 
typedef uint lf_hash_func(const LF_HASH *, const uchar *, size_t)
 
typedef int lf_cmp_func(const uchar *key1, size_t key1_length, const uchar *key2, size_t key2_length)
 
typedef void lf_hash_init_func(uchar *dst, const uchar *src)
 
typedef const uchar *(* hash_get_key_function) (const uchar *arg, size_t *length)
 Callback for extracting key and key length from user data in a LF_HASH. More...
 
typedef int lf_hash_match_func(const uchar *el, void *arg)
 

Functions

void lf_dynarray_init (LF_DYNARRAY *array, uint element_size)
 
void lf_dynarray_destroy (LF_DYNARRAY *array)
 
void * lf_dynarray_value (LF_DYNARRAY *array, uint idx)
 
void * lf_dynarray_lvalue (LF_DYNARRAY *array, uint idx)
 
int lf_dynarray_iterate (LF_DYNARRAY *array, lf_dynarray_func func, void *arg)
 
static void lf_pin (LF_PINS *pins, int pin, void *addr)
 
static void lf_unpin (LF_PINS *pins, int pin)
 
void lf_pinbox_init (LF_PINBOX *pinbox, uint free_ptr_offset, lf_pinbox_free_func *free_func, void *free_func_arg)
 
void lf_pinbox_destroy (LF_PINBOX *pinbox)
 
LF_PINSlf_pinbox_get_pins (LF_PINBOX *pinbox)
 
void lf_pinbox_put_pins (LF_PINS *pins)
 
void lf_pinbox_free (LF_PINS *pins, void *addr)
 
void lf_alloc_init2 (LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset, lf_allocator_func *ctor, lf_allocator_func *dtor)
 Initialize lock-free allocator. More...
 
void lf_alloc_destroy (LF_ALLOCATOR *allocator)
 
uint lf_alloc_pool_count (LF_ALLOCATOR *allocator)
 
static void lf_alloc_direct_free (LF_ALLOCATOR *allocator, void *addr)
 
void * lf_alloc_new (LF_PINS *pins)
 
void lf_hash_init2 (LF_HASH *hash, uint element_size, uint flags, uint key_offset, uint key_length, hash_get_key_function get_key, CHARSET_INFO *charset, lf_hash_func *hash_function, lf_allocator_func *ctor, lf_allocator_func *dtor, lf_hash_init_func *init)
 
void lf_hash_init3 (LF_HASH *hash, uint element_size, uint flags, hash_get_key_function get_key, lf_hash_func *hash_function, lf_cmp_func *cmp_function, lf_allocator_func *ctor, lf_allocator_func *dtor, lf_hash_init_func *init)
 
void lf_hash_destroy (LF_HASH *hash)
 
int lf_hash_insert (LF_HASH *hash, LF_PINS *pins, const void *data)
 
void * lf_hash_search (LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
 Find hash element corresponding to the key. More...
 
int lf_hash_delete (LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
 
static LF_PINSlf_hash_get_pins (LF_HASH *hash)
 
static void lf_hash_put_pins (LF_PINS *pins)
 
static void lf_hash_search_unpin (LF_PINS *pins)
 
void * lf_hash_random_match (LF_HASH *hash, LF_PINS *pins, lf_hash_match_func *match, uint rand_val, void *match_arg)
 Find random hash element which satisfies condition specified by match function. More...
 

Variables

MYSQL_PLUGIN_IMPORT const int LF_HASH_OVERHEAD
 

Macro Definition Documentation

◆ lf_alloc_init

#define lf_alloc_init (   A,
  B,
 
)    lf_alloc_init2(A, B, C, NULL, NULL)

◆ LF_DYNARRAY_LEVEL_LENGTH

#define LF_DYNARRAY_LEVEL_LENGTH   256

◆ LF_DYNARRAY_LEVELS

#define LF_DYNARRAY_LEVELS   4

◆ lf_hash_init

#define lf_hash_init (   A,
  B,
  C,
  D,
  E,
  F,
 
)     lf_hash_init2(A, B, C, D, E, F, G, NULL, NULL, NULL, NULL)

◆ LF_HASH_UNIQUE

#define LF_HASH_UNIQUE   1

◆ LF_PINBOX_PINS

#define LF_PINBOX_PINS   4

◆ LF_PURGATORY_SIZE

#define LF_PURGATORY_SIZE   10

◆ LF_REQUIRE_PINS

#define LF_REQUIRE_PINS (   N)

◆ MY_LF_ERRPTR

#define MY_LF_ERRPTR   ((void *)(intptr)1)

Typedef Documentation

◆ hash_get_key_function

typedef const uchar *(* hash_get_key_function) (const uchar *arg, size_t *length)

Callback for extracting key and key length from user data in a LF_HASH.

Parameters
argPointer to user data.
[out]lengthStore key length here.
Returns
Pointer to key to be hashed.
Note
Was my_hash_get_key, with lots of C-style casting when calling my_hash_init. Renamed to force build error (since signature changed) in case someone keeps following that coding style.

◆ lf_allocator_func

typedef void lf_allocator_func(uchar *)

◆ lf_cmp_func

typedef int lf_cmp_func(const uchar *key1, size_t key1_length, const uchar *key2, size_t key2_length)

◆ lf_dynarray_func

typedef int(* lf_dynarray_func) (void *, void *)

◆ lf_hash_func

typedef uint lf_hash_func(const LF_HASH *, const uchar *, size_t)

◆ lf_hash_init_func

typedef void lf_hash_init_func(uchar *dst, const uchar *src)

◆ lf_hash_match_func

typedef int lf_hash_match_func(const uchar *el, void *arg)

◆ lf_pinbox_free_func

typedef void lf_pinbox_free_func(void *, void *, void *)

Function Documentation

◆ lf_alloc_destroy()

void lf_alloc_destroy ( LF_ALLOCATOR allocator)

◆ lf_alloc_direct_free()

static void lf_alloc_direct_free ( LF_ALLOCATOR allocator,
void *  addr 
)
inlinestatic

◆ lf_alloc_init2()

void lf_alloc_init2 ( LF_ALLOCATOR allocator,
uint  size,
uint  free_ptr_offset,
lf_allocator_func ctor,
lf_allocator_func dtor 
)

Initialize lock-free allocator.

Parameters
allocatorAllocator structure to initialize.
sizeA size of an object to allocate.
free_ptr_offsetAn offset inside the object to a sizeof(void *) memory that is guaranteed to be unused after the object is put in the purgatory. Unused by ANY thread, not only the purgatory owner. This memory will be used to link waiting-to-be-freed objects in a purgatory list.
ctorFunction to be called after object was malloc()'ed.
dtorFunction to be called before object is free()'d.

◆ lf_alloc_new()

void * lf_alloc_new ( LF_PINS pins)

◆ lf_alloc_pool_count()

uint lf_alloc_pool_count ( LF_ALLOCATOR allocator)

◆ lf_dynarray_destroy()

void lf_dynarray_destroy ( LF_DYNARRAY array)

◆ lf_dynarray_init()

void lf_dynarray_init ( LF_DYNARRAY array,
uint  element_size 
)

◆ lf_dynarray_iterate()

int lf_dynarray_iterate ( LF_DYNARRAY array,
lf_dynarray_func  func,
void *  arg 
)

◆ lf_dynarray_lvalue()

void * lf_dynarray_lvalue ( LF_DYNARRAY array,
uint  idx 
)

◆ lf_dynarray_value()

void * lf_dynarray_value ( LF_DYNARRAY array,
uint  idx 
)

◆ lf_hash_delete()

int lf_hash_delete ( LF_HASH hash,
LF_PINS pins,
const void *  key,
uint  keylen 
)

◆ lf_hash_destroy()

void lf_hash_destroy ( LF_HASH hash)

◆ lf_hash_get_pins()

static LF_PINS * lf_hash_get_pins ( LF_HASH hash)
inlinestatic

◆ lf_hash_init2()

void lf_hash_init2 ( LF_HASH hash,
uint  element_size,
uint  flags,
uint  key_offset,
uint  key_length,
hash_get_key_function  get_key,
CHARSET_INFO charset,
lf_hash_func hash_function,
lf_allocator_func ctor,
lf_allocator_func dtor,
lf_hash_init_func init 
)

◆ lf_hash_init3()

void lf_hash_init3 ( LF_HASH hash,
uint  element_size,
uint  flags,
hash_get_key_function  get_key,
lf_hash_func hash_function,
lf_cmp_func cmp_function,
lf_allocator_func ctor,
lf_allocator_func dtor,
lf_hash_init_func init 
)

◆ lf_hash_insert()

int lf_hash_insert ( LF_HASH hash,
LF_PINS pins,
const void *  data 
)

◆ lf_hash_put_pins()

static void lf_hash_put_pins ( LF_PINS pins)
inlinestatic

◆ lf_hash_random_match()

void * lf_hash_random_match ( LF_HASH hash,
LF_PINS pins,
lf_hash_match_func match,
uint  rand_val,
void *  match_arg 
)

Find random hash element which satisfies condition specified by match function.

Parameters
hashHash to search element in.
pinsPins for calling thread to be used during search and for pinning its result.
matchPointer to match function. This function takes pointer to object stored in hash as parameter and returns 0 if object doesn't satisfy its condition (and non-0 value if it does).
rand_valRandom value to be used for selecting hash bucket from which search in sort-ordered list needs to be started.
match_argArgument passed to match function.
Return values
Apointer to a random element matching condition.
NULL- if nothing is found
MY_LF_ERRPTR- OOM.
Note
This function follows the same pinning protocol as lf_hash_search(), i.e. uses pins[0..2]. On return pins[0..1] are removed and pins[2] is used to pin object found. It is also not removed in case when object is not found/error occurs but its value is undefined in this case. So calling lf_hash_unpin() is mandatory after call to this function in case of both success and failure.

◆ lf_hash_search()

void * lf_hash_search ( LF_HASH hash,
LF_PINS pins,
const void *  key,
uint  keylen 
)

Find hash element corresponding to the key.

Parameters
hashThe hash to search element in.
pinsPins for the calling thread which were earlier obtained from this hash using lf_hash_get_pins().
keyKey
keylenKey length
Return values
Apointer to an element with the given key (if a hash is not unique and there're many elements with this key - the "first" matching element).
NULL- if nothing is found
MY_LF_ERRPTR- if OOM
Note
Uses pins[0..2]. On return pins[0..1] are removed and pins[2] is used to pin object found. It is also not removed in case when object is not found/error occurs but pin value is undefined in this case. So calling lf_hash_unpin() is mandatory after call to this function in case of both success and failure.
See also
my_lsearch().

◆ lf_hash_search_unpin()

static void lf_hash_search_unpin ( LF_PINS pins)
inlinestatic

◆ lf_pin()

static void lf_pin ( LF_PINS pins,
int  pin,
void *  addr 
)
inlinestatic

◆ lf_pinbox_destroy()

void lf_pinbox_destroy ( LF_PINBOX pinbox)

◆ lf_pinbox_free()

void lf_pinbox_free ( LF_PINS pins,
void *  addr 
)

◆ lf_pinbox_get_pins()

LF_PINS * lf_pinbox_get_pins ( LF_PINBOX pinbox)

◆ lf_pinbox_init()

void lf_pinbox_init ( LF_PINBOX pinbox,
uint  free_ptr_offset,
lf_pinbox_free_func free_func,
void *  free_func_arg 
)

◆ lf_pinbox_put_pins()

void lf_pinbox_put_pins ( LF_PINS pins)

◆ lf_unpin()

static void lf_unpin ( LF_PINS pins,
int  pin 
)
inlinestatic

Variable Documentation

◆ LF_HASH_OVERHEAD

MYSQL_PLUGIN_IMPORT const int LF_HASH_OVERHEAD
extern