minor changes
This commit is contained in:
parent
d3b18593b4
commit
6799376107
|
@ -17,7 +17,6 @@
|
||||||
#define _TD_UTIL_CACHE_H_
|
#define _TD_UTIL_CACHE_H_
|
||||||
|
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlockfree.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#define _TD_UTIL_CHECKSUM_H_
|
#define _TD_UTIL_CHECKSUM_H_
|
||||||
|
|
||||||
#include "tcrc32c.h"
|
#include "tcrc32c.h"
|
||||||
#include "tutil.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -16,18 +16,28 @@
|
||||||
#ifndef _TD_UTIL_IDPOOL_H_
|
#ifndef _TD_UTIL_IDPOOL_H_
|
||||||
#define _TD_UTIL_IDPOOL_H_
|
#define _TD_UTIL_IDPOOL_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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);
|
void *taosInitIdPool(int32_t maxId);
|
||||||
int32_t taosUpdateIdPool(void *handle, int32_t maxId);
|
int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId);
|
||||||
int32_t taosIdPoolMaxSize(void *handle);
|
int32_t taosIdPoolMaxSize(id_pool_t *handle);
|
||||||
int32_t taosAllocateId(void *handle);
|
int32_t taosAllocateId(id_pool_t *handle);
|
||||||
void taosFreeId(void *handle, int32_t id);
|
void taosFreeId(id_pool_t *handle, int32_t id);
|
||||||
void taosIdPoolCleanUp(void *handle);
|
void taosIdPoolCleanUp(id_pool_t *handle);
|
||||||
int32_t taosIdPoolNumOfUsed(void *handle);
|
int32_t taosIdPoolNumOfUsed(id_pool_t *handle);
|
||||||
bool taosIdPoolMarkStatus(void *handle, int32_t id);
|
bool taosIdPoolMarkStatus(id_pool_t *handle, int32_t id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_UTIL_LOG_H
|
#ifndef _TD_UTIL_LOG_H_
|
||||||
#define _TD_UTIL_LOG_H
|
#define _TD_UTIL_LOG_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -84,4 +84,4 @@ extern int8_t tscEmbeddedInUtil;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_LOG_H*/
|
#endif /*_TD_UTIL_LOG_H_*/
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#ifndef _TD_UTIL_WORKER_H_
|
#ifndef _TD_UTIL_WORKER_H_
|
||||||
#define _TD_UTIL_WORKER_H_
|
#define _TD_UTIL_WORKER_H_
|
||||||
|
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
|
||||||
#ifdef USE_LUCENE
|
#ifdef USE_LUCENE
|
||||||
#include <lucene++/Lucene_c.h>
|
#include <lucene++/Lucene_c.h>
|
||||||
|
|
|
@ -14,16 +14,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "tidpool.h"
|
||||||
#include "tlog.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) {
|
void *taosInitIdPool(int32_t maxId) {
|
||||||
id_pool_t *pIdPool = calloc(1, sizeof(id_pool_t));
|
id_pool_t *pIdPool = calloc(1, sizeof(id_pool_t));
|
||||||
if (pIdPool == NULL) return NULL;
|
if (pIdPool == NULL) return NULL;
|
||||||
|
@ -45,11 +38,8 @@ void *taosInitIdPool(int32_t maxId) {
|
||||||
return pIdPool;
|
return pIdPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosAllocateId(void *handle) {
|
int32_t taosAllocateId(id_pool_t *pIdPool) {
|
||||||
id_pool_t *pIdPool = handle;
|
if (pIdPool == NULL) return -1;
|
||||||
if (handle == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t slot = -1;
|
int32_t slot = -1;
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
@ -70,9 +60,8 @@ int32_t taosAllocateId(void *handle) {
|
||||||
return slot + 1;
|
return slot + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosFreeId(void *handle, int32_t id) {
|
void taosFreeId(id_pool_t *pIdPool, int32_t id) {
|
||||||
id_pool_t *pIdPool = handle;
|
if (pIdPool == NULL) return;
|
||||||
if (handle == NULL) return;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
|
||||||
|
@ -85,9 +74,7 @@ void taosFreeId(void *handle, int32_t id) {
|
||||||
pthread_mutex_unlock(&pIdPool->mutex);
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosIdPoolCleanUp(void *handle) {
|
void taosIdPoolCleanUp(id_pool_t *pIdPool) {
|
||||||
id_pool_t *pIdPool = handle;
|
|
||||||
|
|
||||||
if (pIdPool == NULL) return;
|
if (pIdPool == NULL) return;
|
||||||
|
|
||||||
uDebug("pool:%p is cleaned", pIdPool);
|
uDebug("pool:%p is cleaned", pIdPool);
|
||||||
|
@ -101,9 +88,7 @@ void taosIdPoolCleanUp(void *handle) {
|
||||||
free(pIdPool);
|
free(pIdPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosIdPoolNumOfUsed(void *handle) {
|
int32_t taosIdPoolNumOfUsed(id_pool_t *pIdPool) {
|
||||||
id_pool_t *pIdPool = handle;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
int32_t ret = pIdPool->maxId - pIdPool->numOfFree;
|
int32_t ret = pIdPool->maxId - pIdPool->numOfFree;
|
||||||
pthread_mutex_unlock(&pIdPool->mutex);
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
|
@ -111,9 +96,8 @@ int32_t taosIdPoolNumOfUsed(void *handle) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosIdPoolMarkStatus(void *handle, int32_t id) {
|
bool taosIdPoolMarkStatus(id_pool_t *pIdPool, int32_t id) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
id_pool_t *pIdPool = handle;
|
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
|
|
||||||
int32_t slot = (id - 1) % pIdPool->maxId;
|
int32_t slot = (id - 1) % pIdPool->maxId;
|
||||||
|
@ -129,8 +113,7 @@ bool taosIdPoolMarkStatus(void *handle, int32_t id) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId) {
|
int32_t taosUpdateIdPool(id_pool_t *pIdPool, int32_t maxId) {
|
||||||
id_pool_t *pIdPool = (id_pool_t *)handle;
|
|
||||||
if (maxId <= pIdPool->maxId) {
|
if (maxId <= pIdPool->maxId) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -155,9 +138,7 @@ int32_t taosUpdateIdPool(id_pool_t *handle, int32_t maxId) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosIdPoolMaxSize(void *handle) {
|
int32_t taosIdPoolMaxSize(id_pool_t *pIdPool) {
|
||||||
id_pool_t *pIdPool = (id_pool_t *)handle;
|
|
||||||
|
|
||||||
pthread_mutex_lock(&pIdPool->mutex);
|
pthread_mutex_lock(&pIdPool->mutex);
|
||||||
int32_t ret = pIdPool->maxId;
|
int32_t ret = pIdPool->maxId;
|
||||||
pthread_mutex_unlock(&pIdPool->mutex);
|
pthread_mutex_unlock(&pIdPool->mutex);
|
||||||
|
|
Loading…
Reference in New Issue