item_uthash -> item_rcu && add foreign cont dir API
This commit is contained in:
@@ -26,6 +26,7 @@ struct ex_data_runtime {
|
||||
|
||||
struct rcu_hash_table *htable;
|
||||
struct ex_data_schema *ref_ex_schema;
|
||||
struct maat_garbage_bin *ref_garbage_bin;
|
||||
int table_id;
|
||||
|
||||
struct log_handle *logger;
|
||||
@@ -33,20 +34,21 @@ struct ex_data_runtime {
|
||||
|
||||
void cache_row_free(void *p)
|
||||
{
|
||||
FREE(*(char **)p);
|
||||
free(*(char **)p);
|
||||
}
|
||||
|
||||
UT_icd ut_cache_row_icd = {sizeof(char*), NULL, NULL, cache_row_free};
|
||||
|
||||
struct ex_data_runtime *
|
||||
ex_data_runtime_new(int table_id, rcu_hash_data_free_fn *data_free_fn,
|
||||
struct log_handle *logger)
|
||||
struct maat_garbage_bin *garbage_bin, struct log_handle *logger)
|
||||
{
|
||||
struct ex_data_runtime *ex_data_rt = ALLOC(struct ex_data_runtime, 1);
|
||||
|
||||
utarray_new(ex_data_rt->cache_rows, &ut_cache_row_icd);
|
||||
ex_data_rt->htable = rcu_hash_new(data_free_fn);
|
||||
ex_data_rt->table_id = table_id;
|
||||
ex_data_rt->ref_garbage_bin = garbage_bin;
|
||||
ex_data_rt->logger = logger;
|
||||
|
||||
return ex_data_rt;
|
||||
@@ -137,7 +139,7 @@ struct ex_data_schema *ex_data_schema_new(maat_ex_new_func_t *new_func,
|
||||
|
||||
void ex_data_schema_free(struct ex_data_schema *ex_schema)
|
||||
{
|
||||
FREE(ex_schema);
|
||||
free(ex_schema);
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
@@ -146,16 +148,16 @@ void ex_data_runtime_set_schema(struct ex_data_runtime *ex_data_rt,
|
||||
ex_data_rt->ref_ex_schema = schema;
|
||||
}
|
||||
|
||||
void ex_data_runtime_set_ex_container_ctx(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_ctx *container_ctx)
|
||||
void ex_data_runtime_set_ex_container_schema(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container_schema *container_schema)
|
||||
{
|
||||
rcu_hash_set_user_ctx(ex_data_rt->htable, container_ctx);
|
||||
rcu_hash_set_user_ctx(ex_data_rt->htable, container_schema);
|
||||
}
|
||||
|
||||
struct ex_container_ctx *
|
||||
ex_data_runtime_get_ex_container_ctx(struct ex_data_runtime *ex_data_rt)
|
||||
struct ex_container_schema *
|
||||
ex_data_runtime_get_ex_container_schema(struct ex_data_runtime *ex_data_rt)
|
||||
{
|
||||
return (struct ex_container_ctx *)rcu_hash_get_user_ctx(ex_data_rt->htable);
|
||||
return (struct ex_container_schema *)rcu_hash_get_user_ctx(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char *row,
|
||||
@@ -169,9 +171,9 @@ void *ex_data_runtime_row2ex_data(struct ex_data_runtime *ex_data_rt, const char
|
||||
return ex_data;
|
||||
}
|
||||
|
||||
struct ex_data_container *ex_data_container_new(void *ex_data, void *custom_data)
|
||||
struct ex_container *ex_container_new(void *ex_data, void *custom_data)
|
||||
{
|
||||
struct ex_data_container *ex_container = ALLOC(struct ex_data_container, 1);
|
||||
struct ex_container *ex_container = ALLOC(struct ex_container, 1);
|
||||
|
||||
ex_container->ex_data = ex_data;
|
||||
ex_container->custom_data = custom_data;
|
||||
@@ -179,26 +181,31 @@ struct ex_data_container *ex_data_container_new(void *ex_data, void *custom_data
|
||||
return ex_container;
|
||||
}
|
||||
|
||||
void ex_data_container_free(void *ctx, void *data)
|
||||
void ex_container_free(void *schema, void *data)
|
||||
{
|
||||
if (NULL == ctx || NULL == data) {
|
||||
/* schema is NULL if not call ex_data_runtime_set_ex_container_schema */
|
||||
if (NULL == data) {
|
||||
return;
|
||||
}
|
||||
//TODO:
|
||||
if (NULL == schema) {
|
||||
|
||||
struct ex_container_ctx *container_ctx = (struct ex_container_ctx *)ctx;
|
||||
long argl = container_ctx->ex_schema->argl;
|
||||
void *argp = container_ctx->ex_schema->argp;
|
||||
}
|
||||
|
||||
struct ex_container_schema *container_schema = (struct ex_container_schema *)schema;
|
||||
long argl = container_schema->ex_schema->argl;
|
||||
void *argp = container_schema->ex_schema->argp;
|
||||
|
||||
struct ex_data_container *ex_container = (struct ex_data_container *)data;
|
||||
struct ex_container *ex_container = (struct ex_container *)data;
|
||||
if (ex_container->ex_data != NULL
|
||||
&& container_ctx->ex_schema->free_func != NULL) {
|
||||
container_ctx->ex_schema->free_func(container_ctx->table_id,
|
||||
&& container_schema->ex_schema->free_func != NULL) {
|
||||
container_schema->ex_schema->free_func(container_schema->table_id,
|
||||
&(ex_container->ex_data), argl, argp);
|
||||
}
|
||||
|
||||
if (ex_container->custom_data != NULL
|
||||
&& container_ctx->custom_data_free != NULL) {
|
||||
container_ctx->custom_data_free(ex_container->custom_data);
|
||||
&& container_schema->custom_data_free != NULL) {
|
||||
container_schema->custom_data_free(ex_container->custom_data);
|
||||
}
|
||||
|
||||
FREE(ex_container);
|
||||
@@ -206,12 +213,12 @@ void ex_data_container_free(void *ctx, void *data)
|
||||
|
||||
int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len,
|
||||
struct ex_data_container *ex_container)
|
||||
struct ex_container *ex_container)
|
||||
{
|
||||
struct ex_data_container *tmp_container = NULL;
|
||||
struct ex_container *tmp_container = NULL;
|
||||
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
tmp_container = (struct ex_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (tmp_container != NULL) {
|
||||
log_error(ex_data_rt->logger, MODULE_EX_DATA,
|
||||
"[%s:%d] ex_data_runtime add ex container error: already exist same key:%s",
|
||||
@@ -227,8 +234,8 @@ int ex_data_runtime_add_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *tmp_container = NULL;
|
||||
tmp_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
struct ex_container *tmp_container = NULL;
|
||||
tmp_container = (struct ex_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == tmp_container) {
|
||||
log_error(ex_data_rt->logger, MODULE_EX_DATA,
|
||||
@@ -238,16 +245,16 @@ int ex_data_runtime_del_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
}
|
||||
|
||||
rcu_hash_del(ex_data_rt->htable, key, key_len);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *ex_container = NULL;
|
||||
struct ex_container *ex_container = NULL;
|
||||
|
||||
ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
ex_container = (struct ex_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == ex_container) {
|
||||
return NULL;
|
||||
@@ -262,7 +269,7 @@ void *ex_data_runtime_get_ex_data_by_key(struct ex_data_runtime *ex_data_rt,
|
||||
}
|
||||
|
||||
void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_container *ex_container)
|
||||
struct ex_container *ex_container)
|
||||
{
|
||||
void *dup_ex_data = NULL;
|
||||
ex_data_rt->ref_ex_schema->dup_func(ex_data_rt->table_id, &dup_ex_data,
|
||||
@@ -275,8 +282,8 @@ void *ex_data_runtime_get_ex_data_by_container(struct ex_data_runtime *ex_data_r
|
||||
void *ex_data_runtime_get_custom_data(struct ex_data_runtime *ex_data_rt,
|
||||
const char *key, size_t key_len)
|
||||
{
|
||||
struct ex_data_container *ex_container = NULL;
|
||||
ex_container = (struct ex_data_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
struct ex_container *ex_container = NULL;
|
||||
ex_container = (struct ex_container *)rcu_hash_find(ex_data_rt->htable,
|
||||
key, key_len);
|
||||
if (NULL == ex_container) {
|
||||
return NULL;
|
||||
@@ -290,8 +297,13 @@ size_t ex_data_runtime_ex_container_count(struct ex_data_runtime *ex_data_rt)
|
||||
return rcu_hash_count(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
size_t ex_data_runtime_list_updating_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_data_container ***ex_container)
|
||||
int ex_data_runtime_is_updating(struct ex_data_runtime *ex_data_rt)
|
||||
{
|
||||
return rcu_hash_list_updating_data(ex_data_rt->htable, (void ***)ex_container);
|
||||
}
|
||||
return rcu_hash_is_updating(ex_data_rt->htable);
|
||||
}
|
||||
|
||||
size_t ex_data_runtime_list_ex_container(struct ex_data_runtime *ex_data_rt,
|
||||
struct ex_container ***ex_container)
|
||||
{
|
||||
return rcu_hash_list(ex_data_rt->htable, (void ***)ex_container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user