fix: free cache

This commit is contained in:
xsren 2024-08-06 13:44:42 +08:00
parent 3f25f12187
commit 8989a39865
1 changed files with 9 additions and 14 deletions

View File

@ -1228,16 +1228,11 @@ static void checkRegexCache(void* param, void* tmrId) {
return; return;
} }
if(sRegexCache.exit) { if(sRegexCache.exit) {
code = taosThreadMutexUnlock(&sRegexCache.mutex); goto _exit;
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); goto _exit;
return;
} }
if (taosHashGetSize(sRegexCache.regexHash) >= MAX_REGEX_CACHE_SIZE) { if (taosHashGetSize(sRegexCache.regexHash) >= MAX_REGEX_CACHE_SIZE) {
@ -1251,6 +1246,7 @@ static void checkRegexCache(void* param, void* tmrId) {
ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex); ppUsingRegex = taosHashIterate(sRegexCache.regexHash, ppUsingRegex);
} }
} }
_exit:
code = taosThreadMutexUnlock(&sRegexCache.mutex); code = taosThreadMutexUnlock(&sRegexCache.mutex);
if(code != 0) { if(code != 0) {
uError("[regex cache] checkRegexCache, Failed to unlock mutex"); uError("[regex cache] checkRegexCache, Failed to unlock mutex");
@ -1276,30 +1272,29 @@ int32_t InitRegexCache() {
return -1; return -1;
} }
sRegexCache.exit = false;
if (taosThreadMutexInit(&sRegexCache.mutex, NULL) != 0) {
uError("failed to init mutex");
return -1;
}
sRegexCache.timer = taosTmrStart(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, NULL, sRegexCache.regexCacheTmr); sRegexCache.timer = taosTmrStart(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, NULL, sRegexCache.regexCacheTmr);
if (sRegexCache.timer == NULL) { if (sRegexCache.timer == NULL) {
uError("failed to start regex cache timer"); uError("failed to start regex cache timer");
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; int32_t code = 0;
uInfo("[regex cache] destory regex cache"); uInfo("[regex cache] destory regex cache");
(void)taosTmrStopA(&sRegexCache.timer);
code = taosThreadMutexLock(&sRegexCache.mutex); code = taosThreadMutexLock(&sRegexCache.mutex);
if (code != 0) { if (code != 0) {
uError("[regex cache] Failed to lock mutex"); uError("[regex cache] Failed to lock mutex");
return; return;
} }
(void)taosTmrStopA(&sRegexCache.timer);
sRegexCache.exit = true; sRegexCache.exit = true;
taosHashCleanup(sRegexCache.regexHash); taosHashCleanup(sRegexCache.regexHash);
taosTmrCleanUp(sRegexCache.regexCacheTmr); taosTmrCleanUp(sRegexCache.regexCacheTmr);