fix: cache free
This commit is contained in:
parent
53d115f74a
commit
3f25f12187
|
@ -1213,14 +1213,30 @@ typedef struct RegexCache {
|
||||||
SHashObj *regexHash;
|
SHashObj *regexHash;
|
||||||
void *regexCacheTmr;
|
void *regexCacheTmr;
|
||||||
void *timer;
|
void *timer;
|
||||||
|
TdThreadMutex mutex;
|
||||||
|
bool exit;
|
||||||
} RegexCache;
|
} RegexCache;
|
||||||
static RegexCache sRegexCache;
|
static RegexCache sRegexCache;
|
||||||
#define MAX_REGEX_CACHE_SIZE 20
|
#define MAX_REGEX_CACHE_SIZE 20
|
||||||
#define REGEX_CACHE_CLEAR_TIME 30
|
#define REGEX_CACHE_CLEAR_TIME 30
|
||||||
|
|
||||||
static void checkRegexCache(void* param, void* tmrId) {
|
static void checkRegexCache(void* param, void* tmrId) {
|
||||||
|
int32_t code = 0;
|
||||||
|
code = taosThreadMutexLock(&sRegexCache.mutex);
|
||||||
|
if (code != 0) {
|
||||||
|
uError("[regex cache] checkRegexCache, Failed to lock mutex");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(sRegexCache.exit) {
|
||||||
|
code = taosThreadMutexUnlock(&sRegexCache.mutex);
|
||||||
|
if(code != 0) {
|
||||||
|
uError("[regex cache] checkRegexCache, Failed to unlock mutex");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
(void)taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
(void)taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
||||||
if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
|
if (taosHashGetSize(sRegexCache.regexHash) < MAX_REGEX_CACHE_SIZE) {
|
||||||
|
taosThreadMutexUnlock(&sRegexCache.mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1235,6 +1251,10 @@ static void checkRegexCache(void* param, void* tmrId) {
|
||||||
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
|
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
code = taosThreadMutexUnlock(&sRegexCache.mutex);
|
||||||
|
if(code != 0) {
|
||||||
|
uError("[regex cache] checkRegexCache, Failed to unlock mutex");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void regexCacheFree(void *ppUsingRegex) {
|
void regexCacheFree(void *ppUsingRegex) {
|
||||||
|
@ -1262,14 +1282,31 @@ int32_t InitRegexCache() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (taosThreadMutexInit(&sRegexCache.mutex, NULL) != 0) {
|
||||||
|
uError("failed to init mutex");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
sRegexCache.exit = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyRegexCache(){
|
void DestroyRegexCache(){
|
||||||
|
int32_t code = 0;
|
||||||
uInfo("[regex cache] destory regex cache");
|
uInfo("[regex cache] destory regex cache");
|
||||||
|
code = taosThreadMutexLock(&sRegexCache.mutex);
|
||||||
|
if (code != 0) {
|
||||||
|
uError("[regex cache] Failed to lock mutex");
|
||||||
|
return;
|
||||||
|
}
|
||||||
(void)taosTmrStopA(&sRegexCache.timer);
|
(void)taosTmrStopA(&sRegexCache.timer);
|
||||||
|
sRegexCache.exit = true;
|
||||||
taosHashCleanup(sRegexCache.regexHash);
|
taosHashCleanup(sRegexCache.regexHash);
|
||||||
taosTmrCleanUp(sRegexCache.regexCacheTmr);
|
taosTmrCleanUp(sRegexCache.regexCacheTmr);
|
||||||
|
code = taosThreadMutexUnlock(&sRegexCache.mutex);
|
||||||
|
if (code != 0) {
|
||||||
|
uError("[regex cache] Failed to unlock mutex");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t checkRegexPattern(const char *pPattern) {
|
int32_t checkRegexPattern(const char *pPattern) {
|
||||||
|
@ -1296,7 +1333,6 @@ UsingRegex **getRegComp(const char *pPattern) {
|
||||||
(*ppUsingRegex)->lastUsedTime = taosGetTimestampSec();
|
(*ppUsingRegex)->lastUsedTime = taosGetTimestampSec();
|
||||||
return ppUsingRegex;
|
return ppUsingRegex;
|
||||||
}
|
}
|
||||||
printf("getRegComp , ...");
|
|
||||||
UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
|
UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex));
|
||||||
if (pUsingRegex == NULL) {
|
if (pUsingRegex == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
Loading…
Reference in New Issue