From 2dfcac405ac90db943db3610387fc16255f53aec Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 10 Aug 2020 23:51:53 +0800 Subject: [PATCH] TD-1057 change pthread_t to int64 --- src/os/inc/osSemphone.h | 1 + src/os/src/detail/osSemphone.c | 1 + src/os/src/windows/w64Semphone.c | 4 ++++ src/query/inc/qExecutor.h | 2 +- src/query/src/qExecutor.c | 12 ++++++------ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h index c4fc98988a..fd88d2d798 100644 --- a/src/os/inc/osSemphone.h +++ b/src/os/inc/osSemphone.h @@ -32,6 +32,7 @@ extern "C" { bool taosCheckPthreadValid(pthread_t thread); int64_t taosGetPthreadId(); void taosResetPthread(pthread_t *thread); +bool taosComparePthread(pthread_t first, pthread_t second); #ifdef __cplusplus } diff --git a/src/os/src/detail/osSemphone.c b/src/os/src/detail/osSemphone.c index 1f1ef268c6..74f8859029 100644 --- a/src/os/src/detail/osSemphone.c +++ b/src/os/src/detail/osSemphone.c @@ -21,5 +21,6 @@ bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } int64_t taosGetPthreadId() { return (int64_t)pthread_self(); } void taosResetPthread(pthread_t *thread) { *thread = 0; } +bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; } #endif \ No newline at end of file diff --git a/src/os/src/windows/w64Semphone.c b/src/os/src/windows/w64Semphone.c index 7ed6228228..ded7e41843 100644 --- a/src/os/src/windows/w64Semphone.c +++ b/src/os/src/windows/w64Semphone.c @@ -32,3 +32,7 @@ int64_t taosGetPthreadId() { return (int64_t)pthread_self(); #endif } + +bool taosComparePthread(pthread_t first, pthread_t second) { + return first.p == second.p; +} diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index c7026b45c6..b5487561b2 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -186,7 +186,7 @@ enum { typedef struct SQInfo { void* signature; int32_t code; // error code to returned to client - pthread_t owner; // if it is in execution + int64_t owner; // if it is in execution void* tsdb; int32_t vgId; STableGroupInfo tableGroupInfo; // table id list < only includes the STable list> diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 945e35c9f6..34700a33f3 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -130,8 +130,8 @@ static void finalizeQueryResult(SQueryRuntimeEnv *pRuntimeEnv); (tw)->ekey = (tw)->skey + ((_q)->intervalTime - 1); \ } while (0) -#define SET_STABLE_QUERY_OVER(_q) ((_q)->tableIndex = (_q)->tableqinfoGroupInfo.numOfTables) -#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (_q)->tableqinfoGroupInfo.numOfTables) +#define SET_STABLE_QUERY_OVER(_q) ((_q)->tableIndex = (int32_t)((_q)->tableqinfoGroupInfo.numOfTables)) +#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (int32_t)((_q)->tableqinfoGroupInfo.numOfTables)) // todo move to utility static int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *group); @@ -6378,8 +6378,8 @@ static bool doBuildResCheck(SQInfo* pQInfo) { pthread_mutex_unlock(&pQInfo->lock); // clear qhandle owner - assert(pQInfo->owner == pthread_self()); - taosResetPthread(&pQInfo->owner); + assert(pQInfo->owner == taosGetPthreadId()); + pQInfo->owner = 0; return buildRes; } @@ -6387,7 +6387,7 @@ static bool doBuildResCheck(SQInfo* pQInfo) { bool qTableQuery(qinfo_t qinfo) { SQInfo *pQInfo = (SQInfo *)qinfo; assert(pQInfo && pQInfo->signature == pQInfo); - int64_t threadId = pthread_self(); + int64_t threadId = taosGetPthreadId(); int64_t curOwner = 0; if ((curOwner = atomic_val_compare_exchange_64(&pQInfo->owner, 0, threadId)) != 0) { @@ -6549,7 +6549,7 @@ int32_t qKillQuery(qinfo_t qinfo) { // Wait for the query executing thread being stopped/ // Once the query is stopped, the owner of qHandle will be cleared immediately. - while (taosCheckPthreadValid(pQInfo->owner)) { + while (pQInfo->owner != 0) { taosMsleep(100); } -- GitLab