From df4fdfcab798fe42df5a7eaa9510281eb3c7ed6f Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 20 May 2021 10:08:01 +0800 Subject: [PATCH] uniq_skiplist.[hc]: init function add parameter: allocator_use_lock --- HISTORY | 3 ++- src/common_define.h | 6 ++++++ src/uniq_skiplist.c | 8 +++++--- src/uniq_skiplist.h | 7 ++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/HISTORY b/HISTORY index 52b29af..d46f017 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.51 2021-05-18 +Version 1.51 2021-05-20 * fast_mblock.[hc]: support batch alloc and batch free + * uniq_skiplist.[hc]: init function add parameter: allocator_use_lock Version 1.50 2021-05-11 * add function is_digital_string diff --git a/src/common_define.h b/src/common_define.h index 5356491..88f1c56 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -179,6 +179,12 @@ typedef struct char patch; } Version; +typedef struct +{ + char **strs; + int count; +} str_ptr_array_t; + typedef struct { char *key; diff --git a/src/uniq_skiplist.c b/src/uniq_skiplist.c index 0611bad..bf27f5b 100644 --- a/src/uniq_skiplist.c +++ b/src/uniq_skiplist.c @@ -54,7 +54,7 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, const int max_level_count, skiplist_compare_func compare_func, uniq_skiplist_free_func free_func, const int alloc_skiplist_once, const int min_alloc_elements_once, const int delay_free_seconds, - const bool bidirection) + const bool bidirection, const bool allocator_use_lock) { const int64_t alloc_elements_limit = 0; char name[64]; @@ -105,7 +105,8 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, sizeof(UniqSkiplistNode *) * (i + 1 + extra_links_count); if ((result=fast_mblock_init_ex1(factory->node_allocators + i, name, element_size, alloc_elements_once, - alloc_elements_limit, NULL, NULL, false)) != 0) + alloc_elements_limit, NULL, NULL, + allocator_use_lock)) != 0) { return result; } @@ -117,7 +118,8 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, if ((result=fast_mblock_init_ex1(&factory->skiplist_allocator, "skiplist", sizeof(UniqSkiplist), alloc_skiplist_once > 0 ? alloc_skiplist_once : - 4 * 1024, alloc_elements_limit, NULL, NULL, false)) != 0) + 4 * 1024, alloc_elements_limit, NULL, NULL, + allocator_use_lock)) != 0) { return result; } diff --git a/src/uniq_skiplist.h b/src/uniq_skiplist.h index 1c91e9b..c388598 100644 --- a/src/uniq_skiplist.h +++ b/src/uniq_skiplist.h @@ -75,7 +75,7 @@ extern "C" { delay_free_seconds) \ uniq_skiplist_init_ex2(factory, max_level_count, compare_func, \ free_func, alloc_skiplist_once, min_alloc_elements_once, \ - delay_free_seconds, false) + delay_free_seconds, false, false) #define uniq_skiplist_init(factory, max_level_count, compare_func, free_func) \ uniq_skiplist_init_ex(factory, max_level_count, \ @@ -102,7 +102,7 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, const int max_level_count, skiplist_compare_func compare_func, uniq_skiplist_free_func free_func, const int alloc_skiplist_once, const int min_alloc_elements_once, const int delay_free_seconds, - const bool bidirection); + const bool bidirection, const bool allocator_use_lock); void uniq_skiplist_destroy(UniqSkiplistFactory *factory); @@ -118,12 +118,13 @@ static inline int uniq_skiplist_init_pair_ex(UniqSkiplistPair *pair, const int delay_free_seconds, const bool bidirection) { const int alloc_skiplist_once = 1; + const bool allocator_use_lock = false; int result; if ((result=uniq_skiplist_init_ex2(&pair->factory, max_level_count, compare_func, free_func, alloc_skiplist_once, min_alloc_elements_once, delay_free_seconds, - bidirection)) != 0) + bidirection, allocator_use_lock)) != 0) { return result; }