D.S

dev.mysql.com

MySQL: include/lf.h Source File

MySQL: include/lf.h Source File MySQL  8.0.0 Source Code Documentation Main Page Related Pages Modules Namespaces Classes Files File List File Members lf.h Go to the documentation of this file. 1 /* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. 2  3  This program is free software; you can redistribute it and/or modify 4  it under the terms of the GNU General Public License as published by 5  the Free Software Foundation; version 2 of the License. 6  7  This program is distributed in the hope that it will be useful, 8  but WITHOUT ANY WARRANTY; without even the implied warranty of 9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10  GNU General Public License for more details. 11  12  You should have received a copy of the GNU General Public License 13  along with this program; if not, write to the Free Software 14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15  16 #ifndef _lf_h 17 #define _lf_h 18  19 /** 20  @file include/lf.h 21 */ 22  23 #include " my_global.h " 24 #include " my_atomic.h " 25 #include " hash.h " 26 #include " mysql/service_mysql_alloc.h " 27  28  C_MODE_START 29  30 /* 31  wait-free dynamic array, see lf_dynarray.c 32  33  4 levels of 256 elements each mean 4311810304 elements in an array - it 34  should be enough for a while 35 */ 36  #define LF_DYNARRAY_LEVEL_LENGTH 256 37  #define LF_DYNARRAY_LEVELS 4 38  39  typedef struct { 40   void * volatile level[ LF_DYNARRAY_LEVELS ]; 41   uint size_of_element ; 42 } LF_DYNARRAY ; 43  44  typedef int (* lf_dynarray_func )(void *, void *); 45  46 void lf_dynarray_init ( LF_DYNARRAY *array, uint element_size); 47 void lf_dynarray_destroy ( LF_DYNARRAY *array); 48 void * lf_dynarray_value ( LF_DYNARRAY *array, uint idx); 49 void * lf_dynarray_lvalue ( LF_DYNARRAY *array, uint idx); 50 int lf_dynarray_iterate ( LF_DYNARRAY *array, lf_dynarray_func func, void *arg); 51  52 /* 53  pin manager for memory allocator, lf_alloc-pin.c 54 */ 55  56  #define LF_PINBOX_PINS 4 57  #define LF_PURGATORY_SIZE 10 58  59  typedef void lf_pinbox_free_func (void *, void *, void*); 60  61  typedef struct { 62   LF_DYNARRAY pinarray ; 63   lf_pinbox_free_func * free_func ; 64   void * free_func_arg ; 65   uint free_ptr_offset ; 66   uint32 volatile pinstack_top_ver ; /* this is a versioned pointer */ 67   uint32 volatile pins_in_array ; /* number of elements in array */ 68 } LF_PINBOX ; 69  70  typedef struct st_lf_pins { 71   void * volatile pin [ LF_PINBOX_PINS ]; 72   LF_PINBOX * pinbox ; 73   void * purgatory ; 74   uint32 purgatory_count ; 75   uint32 volatile link ; 76 /* we want sizeof(LF_PINS) to be 64 to avoid false sharing */ 77 #if SIZEOF_INT*2+SIZEOF_CHARP*(LF_PINBOX_PINS+2) != 64 78   char pad [64-sizeof(uint32)*2-sizeof(void*)*( LF_PINBOX_PINS +2)]; 79 #endif 80 } LF_PINS ; 81  82 /* 83  compile-time assert, to require "no less than N" pins 84  it's enough if it'll fail on at least one compiler, so 85  we'll enable it on GCC only, which supports zero-length arrays. 86 */ 87 #if defined(__GNUC__) && defined(MY_LF_EXTRA_DEBUG) 88 #define LF_REQUIRE_PINS(N) \ 89  static const char require_pins[LF_PINBOX_PINS-N] \ 90  MY_ATTRIBUTE ((unused)); \ 91  static const int LF_NUM_PINS_IN_THIS_FILE= N; 92 #else 93  #define LF_REQUIRE_PINS(N) 94 #endif 95  96  static inline void lf_pin ( LF_PINS *pins, int pin , void *addr) 97 { 98 #if defined(__GNUC__) && defined(MY_LF_EXTRA_DEBUG) 99  assert(pin < LF_NUM_PINS_IN_THIS_FILE); 100 #endif 101  my_atomic_storeptr (&pins-> pin [pin], addr); 102 } 103  104  static inline void lf_unpin ( LF_PINS *pins, int pin ) 105 { 106 #if defined(__GNUC__) && defined(MY_LF_EXTRA_DEBUG) 107  assert(pin < LF_NUM_PINS_IN_THIS_FILE); 108 #endif 109  my_atomic_storeptr (&pins-> pin [pin], NULL); 110 } 111  112 void lf_pinbox_init ( LF_PINBOX * pinbox , uint free_ptr_offset, 113  lf_pinbox_free_func *free_func, void * free_func_arg); 114 void lf_pinbox_destroy ( LF_PINBOX *pinbox); 115  LF_PINS * lf_pinbox_get_pins ( LF_PINBOX *pinbox); 116 void lf_pinbox_put_pins ( LF_PINS *pins); 117 void lf_pinbox_free ( LF_PINS *pins, void *addr); 118  119  120 /* 121  memory allocator, lf_alloc-pin.c 122 */ 123  typedef void lf_allocator_func ( uchar *); 124  125  typedef struct st_lf_allocator { 126   LF_PINBOX pinbox ; 127   uchar * volatile top ; 128   uint element_size ; 129   uint32 volatile mallocs ; 130   lf_allocator_func * constructor ; /* called, when an object is malloc()'ed */ 131   lf_allocator_func * destructor ; /* called, when an object is free()'d */ 132 } LF_ALLOCATOR ; 133  134  #define lf_alloc_init(A, B, C) lf_alloc_init2(A, B, C, NULL, NULL) 135 void lf_alloc_init2 ( LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset, 136  lf_allocator_func *ctor, lf_allocator_func *dtor); 137 void lf_alloc_destroy ( LF_ALLOCATOR *allocator); 138  uint lf_alloc_pool_count ( LF_ALLOCATOR *allocator); 139  140  static inline void lf_alloc_direct_free ( LF_ALLOCATOR *al