提交 67993761 编写于 作者: S Shengliang Guan

minor changes

上级 d3b18593
......@@ -17,7 +17,6 @@
#define _TD_UTIL_CACHE_H_
#include "thash.h"
#include "tlockfree.h"
#ifdef __cplusplus
extern "C" {
......
......@@ -17,7 +17,6 @@
#define _TD_UTIL_CHECKSUM_H_
#include "tcrc32c.h"
#include "tutil.h"
#ifdef __cplusplus
extern "C" {
......
......@@ -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
}
......
......@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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_*/
......@@ -15,6 +15,7 @@
#ifndef _TD_UTIL_WORKER_H_
#define _TD_UTIL_WORKER_H_
#include "tqueue.h"
#ifdef __cplusplus
......
......@@ -24,6 +24,7 @@
#include "tchecksum.h"
#include "thash.h"
#include "tlog.h"
#include "tutil.h"
#ifdef USE_LUCENE
#include <lucene++/Lucene_c.h>
......
......@@ -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 taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
bool ret = false;
id_pool_t *pIdPool = handle;
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册