From 6799376107ec6ffe35d32a81b1035fa18ee055fb Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 28 Feb 2022 15:19:00 +0800 Subject: [PATCH] minor changes --- include/util/tcache.h | 1 - include/util/tchecksum.h | 1 - include/util/tidpool.h | 24 +++++++++++++------ include/util/tlog.h | 6 ++--- include/util/tworker.h | 1 + source/libs/index/inc/indexInt.h | 1 + source/util/src/tidpool.c | 41 +++++++++----------------------- 7 files changed, 33 insertions(+), 42 deletions(-) diff --git a/include/util/tcache.h b/include/util/tcache.h index 2156579932..0de3ab3a28 100644 --- a/include/util/tcache.h +++ b/include/util/tcache.h @@ -17,7 +17,6 @@ #define _TD_UTIL_CACHE_H_ #include "thash.h" -#include "tlockfree.h" #ifdef __cplusplus extern "C" { diff --git a/include/util/tchecksum.h b/include/util/tchecksum.h index 438850135b..28fb784c46 100644 --- a/include/util/tchecksum.h +++ b/include/util/tchecksum.h @@ -17,7 +17,6 @@ #define _TD_UTIL_CHECKSUM_H_ #include "tcrc32c.h" -#include "tutil.h" #ifdef __cplusplus extern "C" { diff --git a/include/util/tidpool.h b/include/util/tidpool.h index 8a9e0c2413..8596b439e3 100644 --- a/include/util/tidpool.h +++ b/include/util/tidpool.h @@ -16,18 +16,28 @@ #ifndef _TD_UTIL_IDPOOL_H_ #define _TD_UTIL_IDPOOL_H_ +#include "os.h" + #ifdef __cplusplus extern "C" { #endif +typedef struct { + int32_t maxId; + int32_t numOfFree; + int32_t freeSlot; + bool *freeList; + pthread_mutex_t mutex; +} id_pool_t; + void *taosInitIdPool(int32_t maxId); -int32_t taosUpdateIdPool(void *handle, int32_t maxId); -int32_t taosIdPoolMaxSize(void *handle); -int32_t taosAllocateId(void *handle); -void taosFreeId(void *handle, int32_t id); -void taosIdPoolCleanUp(void *handle); -int32_t taosIdPoolNumOfUsed(void *handle); -bool taosIdPoolMarkStatus(void *handle, int32_t id); +int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId); +int32_t taosIdPoolMaxSize(id_pool_t *handle); +int32_t taosAllocateId(id_pool_t *handle); +void taosFreeId(id_pool_t *handle, int32_t id); +void taosIdPoolCleanUp(id_pool_t *handle); +int32_t taosIdPoolNumOfUsed(id_pool_t *handle); +bool taosIdPoolMarkStatus(id_pool_t *handle, int32_t id); #ifdef __cplusplus } diff --git a/include/util/tlog.h b/include/util/tlog.h index 1c14cc445f..6e6795e9a2 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_UTIL_LOG_H -#define _TD_UTIL_LOG_H +#ifndef _TD_UTIL_LOG_H_ +#define _TD_UTIL_LOG_H_ #include "os.h" @@ -84,4 +84,4 @@ extern int8_t tscEmbeddedInUtil; } #endif -#endif /*_TD_UTIL_LOG_H*/ +#endif /*_TD_UTIL_LOG_H_*/ diff --git a/include/util/tworker.h b/include/util/tworker.h index f9d1ce2337..e6f6bc077c 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -15,6 +15,7 @@ #ifndef _TD_UTIL_WORKER_H_ #define _TD_UTIL_WORKER_H_ + #include "tqueue.h" #ifdef __cplusplus diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index e15075530c..59ed5b79f5 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -24,6 +24,7 @@ #include "tchecksum.h" #include "thash.h" #include "tlog.h" +#include "tutil.h" #ifdef USE_LUCENE #include diff --git a/source/util/src/tidpool.c b/source/util/src/tidpool.c index d7f733b1ae..3ae537eae8 100644 --- a/source/util/src/tidpool.c +++ b/source/util/src/tidpool.c @@ -14,16 +14,9 @@ */ #define _DEFAULT_SOURCE +#include "tidpool.h" #include "tlog.h" -typedef struct { - int32_t maxId; - int32_t numOfFree; - int32_t freeSlot; - bool *freeList; - pthread_mutex_t mutex; -} id_pool_t; - void *taosInitIdPool(int32_t maxId) { id_pool_t *pIdPool = calloc(1, sizeof(id_pool_t)); if (pIdPool == NULL) return NULL; @@ -45,11 +38,8 @@ void *taosInitIdPool(int32_t maxId) { return pIdPool; } -int32_t taosAllocateId(void *handle) { - id_pool_t *pIdPool = handle; - if (handle == NULL) { - return -1; - } +int32_t taosAllocateId(id_pool_t *pIdPool) { + if (pIdPool == NULL) return -1; int32_t slot = -1; pthread_mutex_lock(&pIdPool->mutex); @@ -70,9 +60,8 @@ int32_t taosAllocateId(void *handle) { return slot + 1; } -void taosFreeId(void *handle, int32_t id) { - id_pool_t *pIdPool = handle; - if (handle == NULL) return; +void taosFreeId(id_pool_t *pIdPool, int32_t id) { + if (pIdPool == NULL) return; pthread_mutex_lock(&pIdPool->mutex); @@ -85,9 +74,7 @@ void taosFreeId(void *handle, int32_t id) { pthread_mutex_unlock(&pIdPool->mutex); } -void taosIdPoolCleanUp(void *handle) { - id_pool_t *pIdPool = handle; - +void taosIdPoolCleanUp(id_pool_t *pIdPool) { if (pIdPool == NULL) return; uDebug("pool:%p is cleaned", pIdPool); @@ -101,9 +88,7 @@ void taosIdPoolCleanUp(void *handle) { free(pIdPool); } -int32_t taosIdPoolNumOfUsed(void *handle) { - id_pool_t *pIdPool = handle; - +int32_t taosIdPoolNumOfUsed(id_pool_t *pIdPool) { pthread_mutex_lock(&pIdPool->mutex); int32_t ret = pIdPool->maxId - pIdPool->numOfFree; pthread_mutex_unlock(&pIdPool->mutex); @@ -111,9 +96,8 @@ int32_t taosIdPoolNumOfUsed(void *handle) { return ret; } -bool taosIdPoolMarkStatus(void *handle, int32_t id) { - bool ret = false; - id_pool_t *pIdPool = handle; +bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) { + bool ret = false; pthread_mutex_lock(&pIdPool->mutex); int32_t slot = (id - 1) % pIdPool->maxId; @@ -129,8 +113,7 @@ bool taosIdPoolMarkStatus(void *handle, int32_t id) { return ret; } -int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId) { - id_pool_t *pIdPool = (id_pool_t *)handle; +int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) { if (maxId <= pIdPool->maxId) { return 0; } @@ -155,9 +138,7 @@ int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId) { return 0; } -int32_t taosIdPoolMaxSize(void *handle) { - id_pool_t *pIdPool = (id_pool_t *)handle; - +int32_t taosIdPoolMaxSize(id_pool_t *pIdPool) { pthread_mutex_lock(&pIdPool->mutex); int32_t ret = pIdPool->maxId; pthread_mutex_unlock(&pIdPool->mutex);