CUBRID Engine  latest
lock_free.h File Reference
#include "dbtype_def.h"
#include "lockfree_bitmap.hpp"
#include "porting.h"
#include <cassert>
#include <pthread.h>
Include dependency graph for lock_free.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lf_entry_descriptor
 
struct  lf_tran_entry
 
struct  lf_tran_system
 
struct  lf_freelist
 
struct  lf_hash_table
 
struct  lf_hash_table_iterator
 
class  lf_hash_table_cpp< Key, T >
 
class  lf_hash_table_cpp< Key, T >::iterator
 

Macros

#define VOLATILE_ACCESS(v, t)   (*((t volatile *) &(v)))
 
#define LF_EM_NOT_USING_MUTEX   0
 
#define LF_EM_USING_MUTEX   1
 
#define LF_ENTRY_DESCRIPTOR_INITIALIZER
 
#define LF_NULL_TRANSACTION_ID   ULONG_MAX
 
#define LF_TRAN_ENTRY_INITIALIZER   { 0, LF_NULL_TRANSACTION_ID, NULL, NULL, NULL, -1, false }
 
#define LF_TRAN_SYSTEM_INITIALIZER   { NULL, 0, {}, 0, 0, 100, 0, NULL }
 
#define LF_TRAN_CLEANUP_NECESSARY(e)   ((e)->tran_system->min_active_transaction_id > (e)->last_cleanup_id)
 
#define lf_tran_start_with_mb(entry, incr)   lf_tran_start (entry, incr); MEMORY_BARRIER ()
 
#define lf_tran_end_with_mb(entry)   MEMORY_BARRIER (); lf_tran_end (entry)
 
#define LF_FREELIST_INITIALIZER   { NULL, 0, 0, 0, 0, NULL, NULL }
 
#define LF_LIST_BF_NONE   0x0
 
#define LF_LIST_BF_RETURN_ON_RESTART   ((int) 0x01)
 
#define LF_LIST_BF_RESTART_ON_DUPLICATE   ((int) 0x02) /* Not used for now. */
 
#define LF_LIST_BF_INSERT_GIVEN   ((int) 0x04)
 
#define LF_LIST_BF_FIND_OR_INSERT   ((int) 0x08)
 
#define LF_LIST_BF_LOCK_ON_DELETE   ((int) 0x10)
 
#define LF_LIST_BF_IS_FLAG_SET(bf, flag)   ((*(bf) & (flag)) != 0)
 
#define LF_LIST_BF_SET_FLAG(bf, flag)   (*(bf) = *(bf) | (flag))
 
#define LF_LIST_BR_RESTARTED   ((int) 0x100)
 
#define LF_LIST_BR_DUPLICATE   ((int) 0x200) /* Not used for now. */
 
#define LF_LIST_BR_IS_FLAG_SET(br, flag)   ((*(br) & (flag)))
 
#define LF_LIST_BR_SET_FLAG(br, flag)   (*(br) = *(br) | (flag))
 
#define LF_HASH_TABLE_INITIALIZER   { NULL, NULL, PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL }
 

Typedefs

typedef void *(* LF_ENTRY_ALLOC_FUNC) ()
 
typedef int(* LF_ENTRY_FREE_FUNC) (void *)
 
typedef int(* LF_ENTRY_INITIALIZE_FUNC) (void *)
 
typedef int(* LF_ENTRY_UNINITIALIZE_FUNC) (void *)
 
typedef int(* LF_ENTRY_KEY_COPY_FUNC) (void *src, void *dest)
 
typedef int(* LF_ENTRY_KEY_COMPARE_FUNC) (void *key1, void *key2)
 
typedef unsigned int(* LF_ENTRY_HASH_FUNC) (void *key, int htsize)
 
typedef int(* LF_ENTRY_DUPLICATE_KEY_HANDLER) (void *key, void *existing)
 
typedef struct lf_entry_descriptor LF_ENTRY_DESCRIPTOR
 
typedef struct lf_tran_system LF_TRAN_SYSTEM
 
typedef struct lf_tran_entry LF_TRAN_ENTRY
 
typedef struct lf_freelist LF_FREELIST
 
typedef struct lf_hash_table LF_HASH_TABLE
 
typedef struct lf_hash_table_iterator LF_HASH_TABLE_ITERATOR
 

Functions

unsigned int lf_callback_vpid_hash (void *vpid, int htsize)
 
int lf_callback_vpid_compare (void *vpid_1, void *vpid_2)
 
int lf_callback_vpid_copy (void *src, void *dest)
 
int lf_tran_system_init (LF_TRAN_SYSTEM *sys, int max_threads)
 
void lf_tran_system_destroy (LF_TRAN_SYSTEM *sys)
 
LF_TRAN_ENTRYlf_tran_request_entry (LF_TRAN_SYSTEM *sys)
 
void lf_tran_return_entry (LF_TRAN_ENTRY *entry)
 
void lf_tran_destroy_entry (LF_TRAN_ENTRY *entry)
 
void lf_tran_compute_minimum_transaction_id (LF_TRAN_SYSTEM *sys)
 
void lf_tran_start (LF_TRAN_ENTRY *entry, bool incr)
 
void lf_tran_end (LF_TRAN_ENTRY *entry)
 
int lf_initialize_transaction_systems (int max_threads)
 
void lf_destroy_transaction_systems (void)
 
int lf_stack_push (void **top, void *entry, LF_ENTRY_DESCRIPTOR *edesc)
 
void * lf_stack_pop (void **top, LF_ENTRY_DESCRIPTOR *edesc)
 
int lf_freelist_init (LF_FREELIST *freelist, int initial_blocks, int block_size, LF_ENTRY_DESCRIPTOR *edesc, LF_TRAN_SYSTEM *tran_system)
 
void lf_freelist_destroy (LF_FREELIST *freelist)
 
void * lf_freelist_claim (LF_TRAN_ENTRY *tran_entry, LF_FREELIST *freelist)
 
int lf_freelist_retire (LF_TRAN_ENTRY *tran_entry, LF_FREELIST *freelist, void *entry)
 
int lf_freelist_transport (LF_TRAN_ENTRY *tran_entry, LF_FREELIST *freelist)
 
int lf_io_list_find (void **list_p, void *key, LF_ENTRY_DESCRIPTOR *edesc, void **entry)
 
int lf_io_list_find_or_insert (void **list_p, void *new_entry, LF_ENTRY_DESCRIPTOR *edesc, void **entry)
 
int lf_list_find (LF_TRAN_ENTRY *tran, void **list_p, void *key, int *behavior_flags, LF_ENTRY_DESCRIPTOR *edesc, void **entry)
 
int lf_list_delete (LF_TRAN_ENTRY *tran, void **list_p, void *key, void *locked_entry, int *behavior_flags, LF_ENTRY_DESCRIPTOR *edesc, LF_FREELIST *freelist, int *success)
 
int lf_hash_init (LF_HASH_TABLE *table, LF_FREELIST *freelist, unsigned int hash_size, LF_ENTRY_DESCRIPTOR *edesc)
 
void lf_hash_destroy (LF_HASH_TABLE *table)
 
int lf_hash_find (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void **entry)
 
int lf_hash_find_or_insert (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void **entry, int *inserted)
 
int lf_hash_insert (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void **entry, int *inserted)
 
int lf_hash_insert_given (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void **entry, int *inserted)
 
int lf_hash_delete (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, int *success)
 
int lf_hash_delete_already_locked (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void *locked_entry, int *success)
 
void lf_hash_clear (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table)
 
void lf_hash_create_iterator (LF_HASH_TABLE_ITERATOR *iterator, LF_TRAN_ENTRY *tran_entry, LF_HASH_TABLE *table)
 
void * lf_hash_iterate (LF_HASH_TABLE_ITERATOR *it)
 

Variables

LF_TRAN_SYSTEM spage_saving_Ts
 
LF_TRAN_SYSTEM obj_lock_res_Ts
 
LF_TRAN_SYSTEM obj_lock_ent_Ts
 
LF_TRAN_SYSTEM catalog_Ts
 
LF_TRAN_SYSTEM sessions_Ts
 
LF_TRAN_SYSTEM free_sort_list_Ts
 
LF_TRAN_SYSTEM global_unique_stats_Ts
 
LF_TRAN_SYSTEM hfid_table_Ts
 
LF_TRAN_SYSTEM xcache_Ts
 
LF_TRAN_SYSTEM fpcache_Ts
 
LF_TRAN_SYSTEM dwb_slots_Ts
 

Macro Definition Documentation

#define LF_EM_NOT_USING_MUTEX   0

Definition at line 59 of file lock_free.h.

Referenced by heap_initialize_hfid_table().

#define LF_EM_USING_MUTEX   1

Definition at line 60 of file lock_free.h.

Referenced by logtb_initialize_global_unique_stats_table(), and main().

#define LF_ENTRY_DESCRIPTOR_INITIALIZER
Value:
{ 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, \
NULL, NULL, NULL, NULL, NULL}
#define NULL
Definition: freelistheap.h:34

Definition at line 109 of file lock_free.h.

#define LF_FREELIST_INITIALIZER   { NULL, 0, 0, 0, 0, NULL, NULL }

Definition at line 248 of file lock_free.h.

#define LF_HASH_TABLE_INITIALIZER   { NULL, NULL, PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL }

Definition at line 317 of file lock_free.h.

#define LF_LIST_BF_LOCK_ON_DELETE   ((int) 0x10)
#define LF_LIST_BF_NONE   0x0

Definition at line 269 of file lock_free.h.

#define LF_LIST_BF_RESTART_ON_DUPLICATE   ((int) 0x02) /* Not used for now. */
#define LF_LIST_BF_SET_FLAG (   bf,
  flag 
)    (*(bf) = *(bf) | (flag))

Definition at line 278 of file lock_free.h.

#define LF_LIST_BR_DUPLICATE   ((int) 0x200) /* Not used for now. */

Definition at line 282 of file lock_free.h.

#define LF_LIST_BR_IS_FLAG_SET (   br,
  flag 
)    ((*(br) & (flag)))

Definition at line 283 of file lock_free.h.

#define LF_LIST_BR_SET_FLAG (   br,
  flag 
)    (*(br) = *(br) | (flag))
#define LF_TRAN_CLEANUP_NECESSARY (   e)    ((e)->tran_system->min_active_transaction_id > (e)->last_cleanup_id)

Definition at line 182 of file lock_free.h.

Referenced by lf_freelist_claim(), and lf_freelist_retire().

#define LF_TRAN_ENTRY_INITIALIZER   { 0, LF_NULL_TRANSACTION_ID, NULL, NULL, NULL, -1, false }

Definition at line 150 of file lock_free.h.

#define lf_tran_start_with_mb (   entry,
  incr 
)    lf_tran_start (entry, incr); MEMORY_BARRIER ()
#define LF_TRAN_SYSTEM_INITIALIZER   { NULL, 0, {}, 0, 0, 100, 0, NULL }

Definition at line 179 of file lock_free.h.

#define VOLATILE_ACCESS (   v,
 
)    (*((t volatile *) &(v)))

Definition at line 45 of file lock_free.h.

Typedef Documentation

typedef void*(* LF_ENTRY_ALLOC_FUNC) ()

Definition at line 50 of file lock_free.h.

Definition at line 62 of file lock_free.h.

typedef int(* LF_ENTRY_DUPLICATE_KEY_HANDLER) (void *key, void *existing)

Definition at line 57 of file lock_free.h.

typedef int(* LF_ENTRY_FREE_FUNC) (void *)

Definition at line 51 of file lock_free.h.

typedef unsigned int(* LF_ENTRY_HASH_FUNC) (void *key, int htsize)

Definition at line 56 of file lock_free.h.

typedef int(* LF_ENTRY_INITIALIZE_FUNC) (void *)

Definition at line 52 of file lock_free.h.

typedef int(* LF_ENTRY_KEY_COMPARE_FUNC) (void *key1, void *key2)

Definition at line 55 of file lock_free.h.

typedef int(* LF_ENTRY_KEY_COPY_FUNC) (void *src, void *dest)

Definition at line 54 of file lock_free.h.

typedef int(* LF_ENTRY_UNINITIALIZE_FUNC) (void *)

Definition at line 53 of file lock_free.h.

typedef struct lf_freelist LF_FREELIST

Definition at line 227 of file lock_free.h.

typedef struct lf_hash_table LF_HASH_TABLE

Definition at line 295 of file lock_free.h.

Definition at line 336 of file lock_free.h.

typedef struct lf_tran_entry LF_TRAN_ENTRY

Definition at line 118 of file lock_free.h.

Definition at line 117 of file lock_free.h.

Function Documentation

int lf_callback_vpid_compare ( void *  vpid_1,
void *  vpid_2 
)

Definition at line 154 of file lock_free.c.

References vpid::pageid, and vpid::volid.

int lf_callback_vpid_copy ( void *  src,
void *  dest 
)

Definition at line 169 of file lock_free.c.

References NO_ERROR.

unsigned int lf_callback_vpid_hash ( void *  vpid,
int  htsize 
)

Definition at line 140 of file lock_free.c.

References vpid::pageid, and vpid::volid.

void lf_destroy_transaction_systems ( void  )

Definition at line 520 of file lock_free.c.

References lf_tran_system_destroy(), and tran_systems_initialized.

Referenced by boot_server_all_finalize(), and lf_initialize_transaction_systems().

Here is the caller graph for this function:

void lf_hash_create_iterator ( LF_HASH_TABLE_ITERATOR iterator,
LF_TRAN_ENTRY tran_entry,
LF_HASH_TABLE table 
)
int lf_hash_delete ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
int *  success 
)
int lf_hash_delete_already_locked ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void *  locked_entry,
int *  success 
)
int lf_hash_find ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void **  entry 
)
int lf_hash_find_or_insert ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void **  entry,
int *  inserted 
)
int lf_hash_insert ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void **  entry,
int *  inserted 
)

Definition at line 2118 of file lock_free.c.

References lf_hash_insert_internal(), and LF_LIST_BF_RETURN_ON_RESTART.

Referenced by lf_hash_table_cpp< Key, T >::insert().

Here is the caller graph for this function:

int lf_hash_insert_given ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void **  entry,
int *  inserted 
)

Definition at line 2134 of file lock_free.c.

References assert, lf_hash_insert_internal(), LF_LIST_BF_FIND_OR_INSERT, LF_LIST_BF_INSERT_GIVEN, LF_LIST_BF_RETURN_ON_RESTART, and NULL.

Referenced by lf_hash_table_cpp< Key, T >::insert_given().

Here is the caller graph for this function:

int lf_initialize_transaction_systems ( int  max_threads)

Definition at line 448 of file lock_free.c.

References ER_FAILED, error(), lf_destroy_transaction_systems(), lf_tran_system_init(), NO_ERROR, and tran_systems_initialized.

Referenced by cubthread::initialize_thread_entries().

Here is the caller graph for this function:

void* lf_stack_pop ( void **  top,
LF_ENTRY_DESCRIPTOR edesc 
)

Definition at line 575 of file lock_free.c.

References assert, NULL, OF_GET_PTR_DEREF, and lf_entry_descriptor::of_local_next.

Referenced by lf_freelist_claim().

Here is the caller graph for this function:

int lf_stack_push ( void **  top,
void *  entry,
LF_ENTRY_DESCRIPTOR edesc 
)

Definition at line 545 of file lock_free.c.

References assert, NO_ERROR, NULL, OF_GET_PTR_DEREF, and lf_entry_descriptor::of_local_next.

Referenced by lf_freelist_retire().

Here is the caller graph for this function:

void lf_tran_compute_minimum_transaction_id ( LF_TRAN_SYSTEM sys)
void lf_tran_destroy_entry ( LF_TRAN_ENTRY entry)
void lf_tran_end ( LF_TRAN_ENTRY entry)

Variable Documentation

LF_TRAN_SYSTEM catalog_Ts
LF_TRAN_SYSTEM dwb_slots_Ts
LF_TRAN_SYSTEM fpcache_Ts
LF_TRAN_SYSTEM free_sort_list_Ts
LF_TRAN_SYSTEM obj_lock_ent_Ts

Definition at line 48 of file lock_free.c.

Referenced by cubthread::entry::request_lock_free_transactions().

LF_TRAN_SYSTEM obj_lock_res_Ts

Definition at line 47 of file lock_free.c.

Referenced by cubthread::entry::request_lock_free_transactions().

LF_TRAN_SYSTEM sessions_Ts
LF_TRAN_SYSTEM spage_saving_Ts

Definition at line 46 of file lock_free.c.

Referenced by cubthread::entry::request_lock_free_transactions(), and spage_boot().

LF_TRAN_SYSTEM xcache_Ts