[TD-6169]<fix>: windows dll client can not quit. (#7732)
* [TD-6169]<fix>: windows dll client can not quit. * [TD-6169]<fix>: windows dll client can not quit. * [TD-6169]<fix>: windows dll client can not quit. * [TD-6169]<fix>: windows dll client can not quit. * [TD-6169]<fix>: windows dll client can not quit.
This commit is contained in:
parent
6adde1a826
commit
a47f664cf2
|
@ -123,6 +123,10 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry
|
||||||
void taos_init_imp(void) {
|
void taos_init_imp(void) {
|
||||||
char temp[128] = {0};
|
char temp[128] = {0};
|
||||||
|
|
||||||
|
// In the APIs of other program language, taos_cleanup is not available yet.
|
||||||
|
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
||||||
|
atexit(taos_cleanup);
|
||||||
|
|
||||||
errno = TSDB_CODE_SUCCESS;
|
errno = TSDB_CODE_SUCCESS;
|
||||||
srand(taosGetTimestampSec());
|
srand(taosGetTimestampSec());
|
||||||
deltaToUtcInitOnce();
|
deltaToUtcInitOnce();
|
||||||
|
@ -197,10 +201,6 @@ void taos_init_imp(void) {
|
||||||
|
|
||||||
tscRefId = taosOpenRef(200, tscCloseTscObj);
|
tscRefId = taosOpenRef(200, tscCloseTscObj);
|
||||||
|
|
||||||
// In the APIs of other program language, taos_cleanup is not available yet.
|
|
||||||
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
|
|
||||||
atexit(taos_cleanup);
|
|
||||||
|
|
||||||
tscDebug("client is initialized successfully");
|
tscDebug("client is initialized successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,8 @@ static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT;
|
||||||
static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static SArray* pCacheArrayList = NULL;
|
static SArray* pCacheArrayList = NULL;
|
||||||
static bool stopRefreshWorker = false;
|
static bool stopRefreshWorker = false;
|
||||||
|
static bool refreshWorkerNormalStopped = false;
|
||||||
|
static bool refreshWorkerUnexpectedStopped = false;
|
||||||
|
|
||||||
static void doInitRefreshThread(void) {
|
static void doInitRefreshThread(void) {
|
||||||
pCacheArrayList = taosArrayInit(4, POINTER_BYTES);
|
pCacheArrayList = taosArrayInit(4, POINTER_BYTES);
|
||||||
|
@ -537,8 +539,10 @@ void taosCacheCleanup(SCacheObj *pCacheObj) {
|
||||||
pCacheObj->deleting = 1;
|
pCacheObj->deleting = 1;
|
||||||
|
|
||||||
// wait for the refresh thread quit before destroying the cache object.
|
// wait for the refresh thread quit before destroying the cache object.
|
||||||
// But in the dll, the child thread will be killed before atexit takes effect.So here we only wait for 2 seconds.
|
// But in the dll, the child thread will be killed before atexit takes effect.
|
||||||
for (int i = 0; i < 40&&atomic_load_8(&pCacheObj->deleting) != 0; i++) {
|
while(atomic_load_8(&pCacheObj->deleting) != 0) {
|
||||||
|
if (refreshWorkerNormalStopped) break;
|
||||||
|
if (refreshWorkerUnexpectedStopped) return;
|
||||||
taosMsleep(50);
|
taosMsleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,6 +681,12 @@ static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t
|
||||||
taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup);
|
taosHashCondTraverse(pCacheObj->pHashTable, travHashTableFn, &sup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosCacheRefreshWorkerUnexpectedStopped(void) {
|
||||||
|
if(!refreshWorkerNormalStopped) {
|
||||||
|
refreshWorkerUnexpectedStopped=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void* taosCacheTimedRefresh(void *handle) {
|
void* taosCacheTimedRefresh(void *handle) {
|
||||||
assert(pCacheArrayList != NULL);
|
assert(pCacheArrayList != NULL);
|
||||||
uDebug("cache refresh thread starts");
|
uDebug("cache refresh thread starts");
|
||||||
|
@ -685,6 +695,7 @@ void* taosCacheTimedRefresh(void *handle) {
|
||||||
|
|
||||||
const int32_t SLEEP_DURATION = 500; //500 ms
|
const int32_t SLEEP_DURATION = 500; //500 ms
|
||||||
int64_t count = 0;
|
int64_t count = 0;
|
||||||
|
atexit(taosCacheRefreshWorkerUnexpectedStopped);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
taosMsleep(SLEEP_DURATION);
|
taosMsleep(SLEEP_DURATION);
|
||||||
|
@ -749,6 +760,7 @@ void* taosCacheTimedRefresh(void *handle) {
|
||||||
|
|
||||||
pCacheArrayList = NULL;
|
pCacheArrayList = NULL;
|
||||||
pthread_mutex_destroy(&guard);
|
pthread_mutex_destroy(&guard);
|
||||||
|
refreshWorkerNormalStopped=true;
|
||||||
|
|
||||||
uDebug("cache refresh thread quits");
|
uDebug("cache refresh thread quits");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -763,6 +775,6 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) {
|
||||||
doCacheRefresh(pCacheObj, now, fp);
|
doCacheRefresh(pCacheObj, now, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosStopCacheRefreshWorker() {
|
void taosStopCacheRefreshWorker(void) {
|
||||||
stopRefreshWorker = false;
|
stopRefreshWorker = true;
|
||||||
}
|
}
|
Loading…
Reference in New Issue