From 82225a614c512673ddaa55e561ad98f80af424e3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 13 May 2021 15:33:56 +0800 Subject: [PATCH] TD-4170 --- src/util/inc/tskiplist.h | 1 + src/util/src/tskiplist.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/inc/tskiplist.h b/src/util/inc/tskiplist.h index 2c4d1a86ef..17f5940b49 100644 --- a/src/util/inc/tskiplist.h +++ b/src/util/inc/tskiplist.h @@ -96,6 +96,7 @@ typedef struct tSkipListState { } tSkipListState; typedef struct SSkipList { + unsigned int seed; __compar_fn_t comparFn; __sl_key_fn_t keyFn; pthread_rwlock_t *lock; diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index e3798162e8..c8d21962de 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -50,6 +50,8 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _ pSkipList->len = keyLen; pSkipList->flags = flags; pSkipList->keyFn = fn; + pSkipList->seed = rand(); + if (comparFn == NULL) { pSkipList->comparFn = getKeyComparFunc(keyType); } else { @@ -545,7 +547,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) { const uint32_t factor = 4; int32_t n = 1; - while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) { + while ((rand_r(&(pSkipList->seed)) % factor) == 0 && n <= pSkipList->maxLevel) { n++; } -- GitLab