CUBRID Engine  latest
lock_free.c File Reference
#include "config.h"
#include <assert.h>
#include "porting.h"
#include "lock_free.h"
#include "error_manager.h"
#include "error_code.h"
#include "memory_alloc.h"
Include dependency graph for lock_free.c:

Go to the source code of this file.

Macros

#define pthread_mutex_init(a, b)
 
#define pthread_mutex_destroy(a)
 
#define pthread_mutex_lock(a)   0
 
#define pthread_mutex_trylock(a)   0
 
#define pthread_mutex_unlock(a)
 
#define OF_GET_REF(p, o)   (void * volatile *) (((char *)(p)) + (o))
 
#define OF_GET_PTR(p, o)   (void *) (((char *)(p)) + (o))
 
#define OF_GET_PTR_DEREF(p, o)   (*OF_GET_REF (p,o))
 
#define ADDR_HAS_MARK(p)   (((long long volatile) (p)) & 0x1)
 
#define ADDR_WITH_MARK(p)   ((void * volatile) (((long long volatile) (p)) | 0x1))
 
#define ADDR_STRIP_MARK(p)   ((void * volatile) (((long long volatile) (p)) & (~((long long) 0x1))))
 
#define LF_UNITTEST_INC(lf_stat, incval)
 
#define LF_ASSERT_USE_MUTEX_OR_TRAN_STARTED()
 
#define LF_START_TRAN()   if (!is_tran_started) lf_tran_start_with_mb (tran, false); is_tran_started = true
 
#define LF_START_TRAN_FORCE()   assert (!is_tran_started); lf_tran_start_with_mb (tran, false); is_tran_started = true
 
#define LF_END_TRAN()   if (is_tran_started) lf_tran_end_with_mb (tran)
 
#define LF_END_TRAN_FORCE()   assert (is_tran_started); lf_tran_end_with_mb (tran); is_tran_started = false
 
#define LF_LOCK_ENTRY(tolock)
 
#define LF_UNLOCK_ENTRY()
 
#define LF_UNLOCK_ENTRY_FORCE()
 
#define LF_START_TRAN_FORCE()   assert (!is_tran_started); lf_tran_start_with_mb (tran, false); is_tran_started = true
 
#define LF_PROMOTE_TRAN_FORCE()   assert (is_tran_started); MEMORY_BARRIER (); lf_tran_start_with_mb (tran, true)
 
#define LF_END_TRAN_FORCE()   assert (is_tran_started); lf_tran_end_with_mb (tran); is_tran_started = false
 
#define LF_LOCK_ENTRY(tolock)
 
#define LF_UNLOCK_ENTRY_FORCE()
 

Functions

static int lf_list_insert_internal (LF_TRAN_ENTRY *tran, void **list_p, void *key, int *behavior_flags, LF_ENTRY_DESCRIPTOR *edesc, LF_FREELIST *freelist, void **entry, int *inserted)
 
static int lf_hash_insert_internal (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, int bflags, void **entry, int *inserted)
 
static int lf_hash_delete_internal (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void *locked_entry, int bflags, int *success)
 
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)
 
static int lf_freelist_alloc_block (LF_FREELIST *freelist)
 
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_already_locked (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, void *locked_entry, int *success)
 
int lf_hash_delete (LF_TRAN_ENTRY *tran, LF_HASH_TABLE *table, void *key, 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

static int rv
 
LF_TRAN_SYSTEM spage_saving_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM obj_lock_res_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM obj_lock_ent_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM catalog_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM sessions_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM free_sort_list_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM global_unique_stats_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM hfid_table_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM xcache_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM fpcache_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
LF_TRAN_SYSTEM dwb_slots_Ts = LF_TRAN_SYSTEM_INITIALIZER
 
static bool tran_systems_initialized = false
 
static INT64 lf_hash_size = 0
 
static INT64 lf_inserts = 0
 
static INT64 lf_inserts_restart = 0
 
static INT64 lf_list_inserts = 0
 
static INT64 lf_list_inserts_found = 0
 
static INT64 lf_list_inserts_save_temp_1 = 0
 
static INT64 lf_list_inserts_save_temp_2 = 0
 
static INT64 lf_list_inserts_claim = 0
 
static INT64 lf_list_inserts_fail_link = 0
 
static INT64 lf_list_inserts_success_link = 0
 
static INT64 lf_deletes = 0
 
static INT64 lf_deletes_restart = 0
 
static INT64 lf_list_deletes = 0
 
static INT64 lf_list_deletes_found = 0
 
static INT64 lf_list_deletes_fail_mark_next = 0
 
static INT64 lf_list_deletes_fail_unlink = 0
 
static INT64 lf_list_deletes_success_unlink = 0
 
static INT64 lf_list_deletes_not_found = 0
 
static INT64 lf_list_deletes_not_match = 0
 
static INT64 lf_clears = 0
 
static INT64 lf_retires = 0
 
static INT64 lf_claims = 0
 
static INT64 lf_claims_temp = 0
 
static INT64 lf_transports = 0
 
static INT64 lf_temps = 0
 

Macro Definition Documentation

#define ADDR_HAS_MARK (   p)    (((long long volatile) (p)) & 0x1)

Definition at line 70 of file lock_free.c.

Referenced by lf_hash_iterate(), lf_list_find(), and lf_list_insert_internal().

#define ADDR_STRIP_MARK (   p)    ((void * volatile) (((long long volatile) (p)) & (~((long long) 0x1))))
#define ADDR_WITH_MARK (   p)    ((void * volatile) (((long long volatile) (p)) | 0x1))

Definition at line 71 of file lock_free.c.

Referenced by lf_hash_clear(), lf_hash_init(), and lf_list_delete().

#define LF_ASSERT_USE_MUTEX_OR_TRAN_STARTED ( )
Value:
assert (is_tran_started == !edesc->using_mutex); /* The transaction is started if and only if we don't use mutex */ \
assert (!edesc->using_mutex || entry_mutex) /* If we use mutex, we have a mutex locked. */
#define assert(x)

Referenced by lf_list_insert_internal().

#define LF_END_TRAN ( )    if (is_tran_started) lf_tran_end_with_mb (tran)

Referenced by lf_list_insert_internal().

#define LF_END_TRAN_FORCE ( )    assert (is_tran_started); lf_tran_end_with_mb (tran); is_tran_started = false
#define LF_END_TRAN_FORCE ( )    assert (is_tran_started); lf_tran_end_with_mb (tran); is_tran_started = false
#define LF_LOCK_ENTRY (   tolock)
Value:
assert (edesc->using_mutex); \
assert ((tolock) != NULL); \
assert (entry_mutex == NULL); \
/* entry has a mutex protecting it's members; lock it */ \
entry_mutex = (pthread_mutex_t *) OF_GET_PTR (tolock, edesc->of_mutex); \
rv = pthread_mutex_lock (entry_mutex)
static int rv
Definition: lock_free.c:40
#define assert(x)
#define pthread_mutex_lock(a)
Definition: lock_free.c:37
#define OF_GET_PTR(p, o)
Definition: lock_free.c:64
#define NULL
Definition: freelistheap.h:34

Referenced by lf_list_delete(), and lf_list_insert_internal().

#define LF_LOCK_ENTRY (   tolock)
Value:
assert (edesc->using_mutex); \
assert ((tolock) != NULL); \
assert (entry_mutex == NULL); \
/* entry has a mutex protecting it's members; lock it */ \
entry_mutex = (pthread_mutex_t *) OF_GET_PTR (tolock, edesc->of_mutex); \
rv = pthread_mutex_lock (entry_mutex)
static int rv
Definition: lock_free.c:40
#define assert(x)
#define pthread_mutex_lock(a)
Definition: lock_free.c:37
#define OF_GET_PTR(p, o)
Definition: lock_free.c:64
#define NULL
Definition: freelistheap.h:34
#define LF_PROMOTE_TRAN_FORCE ( )    assert (is_tran_started); MEMORY_BARRIER (); lf_tran_start_with_mb (tran, true)

Referenced by lf_list_delete().

#define LF_START_TRAN ( )    if (!is_tran_started) lf_tran_start_with_mb (tran, false); is_tran_started = true
#define LF_START_TRAN_FORCE ( )    assert (!is_tran_started); lf_tran_start_with_mb (tran, false); is_tran_started = true
#define LF_START_TRAN_FORCE ( )    assert (!is_tran_started); lf_tran_start_with_mb (tran, false); is_tran_started = true
#define LF_UNLOCK_ENTRY ( )
Value:
if (edesc->using_mutex && entry_mutex) \
{ \
pthread_mutex_unlock (entry_mutex); \
entry_mutex = NULL; \
}
#define pthread_mutex_unlock(a)
Definition: lock_free.c:39
#define NULL
Definition: freelistheap.h:34

Referenced by lf_list_insert_internal().

#define LF_UNLOCK_ENTRY_FORCE ( )
Value:
assert (edesc->using_mutex && entry_mutex != NULL); \
pthread_mutex_unlock (entry_mutex); \
entry_mutex = NULL
#define assert(x)
#define pthread_mutex_unlock(a)
Definition: lock_free.c:39
#define NULL
Definition: freelistheap.h:34

Referenced by lf_list_delete(), and lf_list_insert_internal().

#define LF_UNLOCK_ENTRY_FORCE ( )
Value:
assert (edesc->using_mutex && entry_mutex != NULL); \
pthread_mutex_unlock (entry_mutex); \
entry_mutex = NULL
#define assert(x)
#define pthread_mutex_unlock(a)
Definition: lock_free.c:39
#define NULL
Definition: freelistheap.h:34
#define OF_GET_PTR (   p,
 
)    (void *) (((char *)(p)) + (o))
#define OF_GET_REF (   p,
 
)    (void * volatile *) (((char *)(p)) + (o))
#define pthread_mutex_destroy (   a)

Definition at line 36 of file lock_free.c.

Referenced by lf_hash_destroy().

#define pthread_mutex_init (   a,
 
)

Definition at line 35 of file lock_free.c.

Referenced by lf_hash_init().

#define pthread_mutex_lock (   a)    0
#define pthread_mutex_trylock (   a)    0

Definition at line 38 of file lock_free.c.

Referenced by pgbuf_is_hit_ratio_low().

#define pthread_mutex_unlock (   a)

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 
)
static int lf_hash_delete_internal ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
void *  locked_entry,
int  bflags,
int *  success 
)
static
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:

static int lf_hash_insert_internal ( LF_TRAN_ENTRY tran,
LF_HASH_TABLE table,
void *  key,
int  bflags,
void **  entry,
int *  inserted 
)
static
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

INT64 lf_claims = 0
static

Definition at line 107 of file lock_free.c.

Referenced by lf_freelist_claim(), and lf_hash_iterate().

INT64 lf_claims_temp = 0
static

Definition at line 108 of file lock_free.c.

Referenced by lf_freelist_claim(), and lf_hash_iterate().

INT64 lf_clears = 0
static

Definition at line 104 of file lock_free.c.

Referenced by lf_hash_clear(), and lf_hash_iterate().

INT64 lf_deletes = 0
static

Definition at line 94 of file lock_free.c.

Referenced by lf_hash_delete_internal(), and lf_hash_iterate().

INT64 lf_deletes_restart = 0
static

Definition at line 95 of file lock_free.c.

Referenced by lf_hash_delete_internal(), and lf_hash_iterate().

INT64 lf_hash_size = 0
static
INT64 lf_inserts = 0
static

Definition at line 84 of file lock_free.c.

Referenced by lf_hash_insert_internal(), and lf_hash_iterate().

INT64 lf_inserts_restart = 0
static

Definition at line 85 of file lock_free.c.

Referenced by lf_hash_insert_internal(), and lf_hash_iterate().

INT64 lf_list_deletes = 0
static

Definition at line 96 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_fail_mark_next = 0
static

Definition at line 98 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_fail_unlink = 0
static

Definition at line 99 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_found = 0
static

Definition at line 97 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_not_found = 0
static

Definition at line 101 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_not_match = 0
static

Definition at line 102 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_deletes_success_unlink = 0
static

Definition at line 100 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_delete().

INT64 lf_list_inserts = 0
static

Definition at line 86 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_claim = 0
static

Definition at line 90 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_fail_link = 0
static

Definition at line 91 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_found = 0
static

Definition at line 87 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_save_temp_1 = 0
static

Definition at line 88 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_save_temp_2 = 0
static

Definition at line 89 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_list_inserts_success_link = 0
static

Definition at line 92 of file lock_free.c.

Referenced by lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_retires = 0
static

Definition at line 106 of file lock_free.c.

Referenced by lf_freelist_retire(), and lf_hash_iterate().

INT64 lf_temps = 0
static

Definition at line 110 of file lock_free.c.

Referenced by lf_freelist_claim(), lf_hash_iterate(), and lf_list_insert_internal().

INT64 lf_transports = 0
static

Definition at line 109 of file lock_free.c.

Referenced by lf_freelist_transport(), and lf_hash_iterate().

bool tran_systems_initialized = false
static