未验证 提交 2aba1e64 编写于 作者: wafwerar's avatar wafwerar 提交者: GitHub

Merge pull request #7781 from...

Merge pull request #7781 from taosdata/hotfix/ZhiqiangWang/TD-6169-windows-dll-client-can-not-quit-problem

[TD-6169]<fix>: windows dll client can not quit.
...@@ -122,6 +122,10 @@ int32_t tscAcquireRpc(const char *key, const char *user, const char *secretEncry ...@@ -122,6 +122,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());
...@@ -197,10 +201,6 @@ void taos_init_imp(void) { ...@@ -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; ...@@ -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,7 +539,10 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { ...@@ -537,7 +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.
while(atomic_load_8(&pCacheObj->deleting) != 0) { while(atomic_load_8(&pCacheObj->deleting) != 0) {
if (refreshWorkerNormalStopped) break;
if (refreshWorkerUnexpectedStopped) return;
taosMsleep(50); taosMsleep(50);
} }
...@@ -676,6 +681,12 @@ static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t ...@@ -676,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");
...@@ -684,6 +695,7 @@ void* taosCacheTimedRefresh(void *handle) { ...@@ -684,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);
...@@ -748,6 +760,7 @@ void* taosCacheTimedRefresh(void *handle) { ...@@ -748,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;
...@@ -762,6 +775,6 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) { ...@@ -762,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;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册