CUBRID Engine  latest
api_handle.c File Reference
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include "api_handle.h"
#include "api_util.h"
#include "error_code.h"
Include dependency graph for api_handle.c:

Go to the source code of this file.

Classes

struct  bh_root_s
 
struct  bhifs_node_s
 
struct  bh_context_fe_s
 
struct  bh_context_be_s
 
struct  sh_context_be_s
 

Macros

#define bhifs_node_init(n, h, b)
 
#define bhifs_node_prune(n)
 
#define bhifs_node_prune_and_register_root(fe, n)
 
#define RR_LOCK()   API_LOCK(&rr_mutex)
 
#define RR_UNLOCK()   API_UNLOCK(&rr_mutex)
 
#define MAX_NUM_ROOTS   1024
 
#define BH_RID_BITS   16
 
#define BH_RID_OFFSET   48
 
#define BH_RID_MASK   0xffff000000000000ULL
 
#define BH_RID_FILTER(h)   (0xffffULL & (h))
 
#define BH_ID_BITS   48
 
#define BH_ID_OFFSET   0
 
#define BH_ID_MASK   0x0000ffffffffffffULL
 
#define BH_ID_FILTER(h)   (0xffffffffffffULL & (h))
 
#define BH_MAKE(rr_, id_)
 
#define BH_GET_RID(h)   BH_RID_FILTER(((h)&BH_RID_MASK)>>BH_RID_OFFSET)
 
#define BH_SET_RID(h, r)   h = (((r)<<BH_RID_OFFSET)&BH_RID_MASK) | ((h) & ~BH_RID_MASK)
 
#define BH_GET_ID(h)   BH_ID_FILTER(((h)&BH_ID_MASK)>>BH_ID_OFFSET)
 
#define BH_SET_ID(h, r)   h = (((r)<<BH_ID_OFFSET)&BH_ID_MASK) | ((h) & ~BH_ID_MASK)
 

Typedefs

typedef struct bh_root_s BH_ROOT
 
typedef struct bhifs_node_s BHIFS_NODE
 
typedef struct bh_context_fe_s bh_context_fe
 
typedef struct bh_context_be_s bh_context_be
 
typedef struct sh_context_be_s sh_context_be
 

Functions

static int rr_next_handle (bh_provider *bh, BIND_HANDLE *rv)
 
static int rr_lazy_init (void)
 
static int bri_init_root (void)
 
static int bri_alloc_root (int *rrid, BH_ROOT **root)
 
static int bri_access_root (int rrid, BH_ROOT **root)
 
static int fe_alloc_handle (BH_INTERFACE *bhifs, BH_BIND *bind, BIND_HANDLE *bh)
 
static int fe_destroy_handle_worker (bh_context_fe *fe, BHIFS_NODE *node)
 
static int fe_destroy_handle (BH_INTERFACE *bhifs, BIND_HANDLE bh)
 
static int fe_lookup (BH_INTERFACE *bhifs, BIND_HANDLE bh, BH_BIND **bind)
 
static int fe_bind_to_handle (BH_INTERFACE *bhifs, BH_BIND *bind, BIND_HANDLE *bh)
 
static int fe_bind_get_parent (BH_INTERFACE *bhifs, BH_BIND *bind, BH_BIND **pbind)
 
static int fe_bind_prune (BH_INTERFACE *bhifs, BH_BIND *bind)
 
static int fe_bind_graft (BH_INTERFACE *bhifs, BH_BIND *bind, BH_BIND *pbind)
 
static int fe_bind_get_first_child (BH_INTERFACE *bhifs, BH_BIND *bind, BH_BIND **pchild)
 
static int fe_bind_get_next_sibling (BH_INTERFACE *bhifs, BH_BIND *bind, BH_BIND **psibling)
 
static int fe_bind_map_worker (bh_context_fe *fe, BHIFS_NODE *node, bh_mapf mf, void *arg)
 
static int fe_bind_map (BH_INTERFACE *bhifs, BH_BIND *bind, bh_mapf mf, void *arg)
 
static void fe_destroy (BH_INTERFACE *bhifs)
 
static int sh_comparef (void *key1, void *key2, int *rc)
 
static int sh_hashf (void *key, unsigned int *rv)
 
static int sh_keyf (void *elem, void **rk)
 
static void sh_destroy (bh_context_be *be)
 
static int sh_lookup (bh_context_be *be, BIND_HANDLE handle, BHIFS_NODE **node)
 
static int sh_insert (bh_context_be *be, BHIFS_NODE *const node)
 
static int sh_delete (bh_context_be *be, BIND_HANDLE handle, BHIFS_NODE **node)
 
static int be_create_static_hash (bh_context_be **be, int bucket_sz)
 
static void rr_init_root (BH_ROOT *root, int i)
 
int bh_get_rid (BIND_HANDLE bh, int *rid)
 
int bh_root_acquire (int *rrid, BH_ROOT_TYPE rt)
 
int bh_root_release (int rrid)
 
int bh_root_lock (int rrid, BH_INTERFACE **bhifs)
 
int bh_root_unlock (int rrid)
 
int create_handle_context (bh_provider *prov, BH_ROOT_TYPE rt, BH_INTERFACE **bhifs)
 

Variables

static API_MUTEX rr_mutex = API_MUTEX_INITIALIZER
 
static int rr_initialized = 0
 
static BH_ROOTrr_free_list
 
static BH_ROOT Roots [MAX_NUM_ROOTS]
 
static int rr_alloc_count = 0
 

Macro Definition Documentation

#define BH_GET_ID (   h)    BH_ID_FILTER(((h)&BH_ID_MASK)>>BH_ID_OFFSET)

Definition at line 135 of file api_handle.c.

#define BH_GET_RID (   h)    BH_RID_FILTER(((h)&BH_RID_MASK)>>BH_RID_OFFSET)

Definition at line 129 of file api_handle.c.

Referenced by bh_get_rid().

#define BH_ID_BITS   48

Definition at line 120 of file api_handle.c.

#define BH_ID_FILTER (   h)    (0xffffffffffffULL & (h))

Definition at line 123 of file api_handle.c.

#define BH_ID_MASK   0x0000ffffffffffffULL

Definition at line 122 of file api_handle.c.

#define BH_ID_OFFSET   0

Definition at line 121 of file api_handle.c.

#define BH_MAKE (   rr_,
  id_ 
)
Value:
#define BH_RID_FILTER(h)
Definition: api_handle.c:118
#define BH_ID_FILTER(h)
Definition: api_handle.c:123
#define BH_ID_MASK
Definition: api_handle.c:122
#define BH_RID_OFFSET
Definition: api_handle.c:116
#define BH_ID_OFFSET
Definition: api_handle.c:121
#define BH_RID_MASK
Definition: api_handle.c:117

Definition at line 125 of file api_handle.c.

Referenced by rr_next_handle().

#define BH_RID_BITS   16

Definition at line 115 of file api_handle.c.

#define BH_RID_FILTER (   h)    (0xffffULL & (h))

Definition at line 118 of file api_handle.c.

#define BH_RID_MASK   0xffff000000000000ULL

Definition at line 117 of file api_handle.c.

#define BH_RID_OFFSET   48

Definition at line 116 of file api_handle.c.

#define BH_SET_ID (   h,
 
)    h = (((r)<<BH_ID_OFFSET)&BH_ID_MASK) | ((h) & ~BH_ID_MASK)

Definition at line 138 of file api_handle.c.

#define BH_SET_RID (   h,
 
)    h = (((r)<<BH_RID_OFFSET)&BH_RID_MASK) | ((h) & ~BH_RID_MASK)

Definition at line 132 of file api_handle.c.

#define bhifs_node_init (   n,
  h,
 
)
Value:
do { \
dlisth_init(&(n)->head); \
(n)->handle = (h); \
(n)->bind = (b); \
(b)->bptr = (n); \
(n)->parent = NULL; \
dlisth_init(&(n)->children); \
} while (0)
void * handle
#define NULL
Definition: freelistheap.h:34
#define dlisth_init(h)
Definition: api_util.h:42

Definition at line 59 of file api_handle.c.

Referenced by fe_alloc_handle().

#define bhifs_node_prune (   n)
Value:
do { \
(n)->parent = NULL; \
} while (0)
#define dlisth_delete(h_)
Definition: api_util.h:50
#define NULL
Definition: freelistheap.h:34

Definition at line 69 of file api_handle.c.

Referenced by fe_bind_graft(), fe_destroy(), and fe_destroy_handle_worker().

#define bhifs_node_prune_and_register_root (   fe,
 
)
Value:
do { \
dlisth_insert_after((dlisth *)(n),&(fe)->root_handles); \
} while(0)
#define dlisth_insert_after(ih, bh)
Definition: api_util.h:68
#define bhifs_node_prune(n)
Definition: api_handle.c:69

Definition at line 75 of file api_handle.c.

Referenced by fe_bind_prune().

#define MAX_NUM_ROOTS   1024

Definition at line 109 of file api_handle.c.

Referenced by bri_alloc_root().

#define RR_LOCK ( )    API_LOCK(&rr_mutex)

Definition at line 107 of file api_handle.c.

Referenced by bh_root_acquire(), bh_root_release(), and rr_lazy_init().

#define RR_UNLOCK ( )    API_UNLOCK(&rr_mutex)

Definition at line 108 of file api_handle.c.

Referenced by bh_root_acquire(), bh_root_release(), and rr_lazy_init().

Typedef Documentation

Definition at line 37 of file api_handle.c.

Definition at line 36 of file api_handle.c.

typedef struct bh_root_s BH_ROOT

Definition at line 34 of file api_handle.c.

typedef struct bhifs_node_s BHIFS_NODE

Definition at line 35 of file api_handle.c.

Definition at line 38 of file api_handle.c.

Function Documentation

int bh_get_rid ( BIND_HANDLE  bh,
int *  rid 
)

Definition at line 802 of file api_handle.c.

References BH_GET_RID, ER_INTERFACE_INVALID_HANDLE, NO_ERROR, and NULL.

Referenced by ci_stmt_close().

Here is the caller graph for this function:

int bh_root_acquire ( int *  rrid,
BH_ROOT_TYPE  rt 
)
int bh_root_lock ( int  rrid,
BH_INTERFACE **  bhifs 
)
int bh_root_release ( int  rrid)
int bh_root_unlock ( int  rrid)

Definition at line 944 of file api_handle.c.

References API_UNLOCK, bri_access_root(), ER_INTERFACE_GENERIC, bh_root_s::mutex, NO_ERROR, and rr_initialized.

Referenced by ci_create_connection_impl(), and ci_stmt_close().

Here is the caller graph for this function:

static int bri_access_root ( int  rrid,
BH_ROOT **  root 
)
static

Definition at line 279 of file api_handle.c.

References ER_INTERFACE_INVALID_HANDLE, NO_ERROR, rr_alloc_count, and bh_root_s::rrid.

Referenced by bh_root_lock(), bh_root_release(), and bh_root_unlock().

Here is the caller graph for this function:

static int bri_alloc_root ( int *  rrid,
BH_ROOT **  root 
)
static

Definition at line 260 of file api_handle.c.

References ER_INTERFACE_TOO_MANY_CONNECTION, MAX_NUM_ROOTS, NO_ERROR, rr_alloc_count, rr_init_root(), and bh_root_s::rrid.

Referenced by bh_root_acquire().

Here is the caller graph for this function:

static int bri_init_root ( void  )
static

Definition at line 248 of file api_handle.c.

References NO_ERROR.

Referenced by rr_lazy_init().

Here is the caller graph for this function:

static int fe_alloc_handle ( BH_INTERFACE bhifs,
BH_BIND bind,
BIND_HANDLE bh 
)
static
static int fe_bind_get_first_child ( BH_INTERFACE bhifs,
BH_BIND bind,
BH_BIND **  pchild 
)
static

Definition at line 513 of file api_handle.c.

References assert, bhifs_node_s::bind, bh_bind_s::bptr, bhifs_node_s::children, dlisth_is_empty, dlisth_s::next, NO_ERROR, and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_get_next_sibling ( BH_INTERFACE bhifs,
BH_BIND bind,
BH_BIND **  psibling 
)
static

Definition at line 542 of file api_handle.c.

References assert, bhifs_node_s::bind, bh_bind_s::bptr, bhifs_node_s::children, bhifs_node_s::head, dlisth_s::next, NO_ERROR, NULL, and bhifs_node_s::parent.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_get_parent ( BH_INTERFACE bhifs,
BH_BIND bind,
BH_BIND **  pbind 
)
static

Definition at line 435 of file api_handle.c.

References assert, bhifs_node_s::bind, bh_bind_s::bptr, NO_ERROR, NULL, and bhifs_node_s::parent.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_graft ( BH_INTERFACE bhifs,
BH_BIND bind,
BH_BIND pbind 
)
static

Definition at line 484 of file api_handle.c.

References assert, bhifs_node_prune, bh_bind_s::bptr, bhifs_node_s::children, dlisth_insert_before, NO_ERROR, NULL, and bhifs_node_s::parent.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_map ( BH_INTERFACE bhifs,
BH_BIND bind,
bh_mapf  mf,
void *  arg 
)
static

Definition at line 596 of file api_handle.c.

References assert, bh_bind_s::bptr, fe_bind_map_worker(), and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_map_worker ( bh_context_fe fe,
BHIFS_NODE node,
bh_mapf  mf,
void *  arg 
)
static

Definition at line 572 of file api_handle.c.

References bhifs_node_s::bind, bhifs_node_s::children, dlisth_s::next, and NO_ERROR.

Referenced by fe_bind_map().

Here is the caller graph for this function:

static int fe_bind_prune ( BH_INTERFACE bhifs,
BH_BIND bind 
)
static

Definition at line 460 of file api_handle.c.

References assert, bh_root_s::bhifs, bhifs_node_prune_and_register_root, bh_bind_s::bptr, NO_ERROR, and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_bind_to_handle ( BH_INTERFACE bhifs,
BH_BIND bind,
BIND_HANDLE bh 
)
static

Definition at line 413 of file api_handle.c.

References assert, bh_bind_s::bptr, bhifs_node_s::handle, NO_ERROR, and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static void fe_destroy ( BH_INTERFACE bhifs)
static
static int fe_destroy_handle ( BH_INTERFACE bhifs,
BIND_HANDLE  bh 
)
static

Definition at line 365 of file api_handle.c.

References assert, bh_context_fe_s::be, fe_destroy_handle_worker(), bh_context_be_s::lookup, NO_ERROR, and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static int fe_destroy_handle_worker ( bh_context_fe fe,
BHIFS_NODE node 
)
static
static int fe_lookup ( BH_INTERFACE bhifs,
BIND_HANDLE  bh,
BH_BIND **  bind 
)
static

Definition at line 388 of file api_handle.c.

References assert, bh_context_fe_s::be, bhifs_node_s::bind, bh_context_be_s::lookup, NO_ERROR, and NULL.

Referenced by create_handle_context().

Here is the caller graph for this function:

static void rr_init_root ( BH_ROOT root,
int  i 
)
static

Definition at line 233 of file api_handle.c.

References API_MUTEX_INIT, bh_root_s::bhifs, bh_root_s::free_link, i, bh_root_s::mutex, bh_provider_s::next_handle, NULL, bh_root_s::provider, rr_next_handle(), bh_root_s::rrid, and bh_root_s::rrv.

Referenced by bri_alloc_root().

Here is the caller graph for this function:

static int rr_lazy_init ( void  )
static

Definition at line 202 of file api_handle.c.

References bri_init_root(), NO_ERROR, NULL, rr_initialized, RR_LOCK, and RR_UNLOCK.

Referenced by bh_root_acquire().

Here is the caller graph for this function:

static int rr_next_handle ( bh_provider bh,
BIND_HANDLE rv 
)
static

Definition at line 186 of file api_handle.c.

References assert, BH_MAKE, NO_ERROR, NULL, bh_root_s::rrid, and bh_root_s::rrv.

Referenced by rr_init_root().

Here is the caller graph for this function:

static int sh_comparef ( void *  key1,
void *  key2,
int *  rc 
)
static

Definition at line 645 of file api_handle.c.

References assert, NO_ERROR, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static int sh_delete ( bh_context_be be,
BIND_HANDLE  handle,
BHIFS_NODE **  node 
)
static

Definition at line 754 of file api_handle.c.

References assert, hash_delete(), sh_context_be_s::ht, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static void sh_destroy ( bh_context_be be)
static

Definition at line 703 of file api_handle.c.

References API_FREE, assert, hash_destroy(), sh_context_be_s::ht, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static int sh_hashf ( void *  key,
unsigned int *  rv 
)
static

Definition at line 666 of file api_handle.c.

References assert, NO_ERROR, NULL, and p.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static int sh_insert ( bh_context_be be,
BHIFS_NODE *const  node 
)
static

Definition at line 737 of file api_handle.c.

References assert, hash_insert(), sh_context_be_s::ht, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static int sh_keyf ( void *  elem,
void **  rk 
)
static

Definition at line 685 of file api_handle.c.

References assert, bhifs_node_s::handle, NO_ERROR, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

static int sh_lookup ( bh_context_be be,
BIND_HANDLE  handle,
BHIFS_NODE **  node 
)
static

Definition at line 722 of file api_handle.c.

References assert, hash_lookup(), sh_context_be_s::ht, and NULL.

Referenced by be_create_static_hash().

Here is the caller graph for this function:

Variable Documentation

BH_ROOT Roots[MAX_NUM_ROOTS]
static

Definition at line 176 of file api_handle.c.

int rr_alloc_count = 0
static

Definition at line 177 of file api_handle.c.

Referenced by bri_access_root(), and bri_alloc_root().

BH_ROOT* rr_free_list
static

Definition at line 175 of file api_handle.c.

Referenced by bh_root_acquire(), and bh_root_release().

int rr_initialized = 0
static

Definition at line 174 of file api_handle.c.

Referenced by bh_root_lock(), bh_root_unlock(), and rr_lazy_init().

API_MUTEX rr_mutex = API_MUTEX_INITIALIZER
static

Definition at line 173 of file api_handle.c.