diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index aa9dae4001d6b9c74c30ad36572aca7967edff24..71953dc4dcf596b0f9f528ed243614f92c37a6d1 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2581,7 +2581,7 @@ bool tscSetSqlOwner(SSqlObj* pSql) { #ifdef __APPLE__ pthread_t threadId = (pthread_t)taosGetSelfPthreadId(); #else // __APPLE__ - uint64_t threadId = taosGetSelfPthreadId(); + int64_t threadId = taosGetSelfPthreadId(); #endif // __APPLE__ if (atomic_val_compare_exchange_64(&pSql->owner, 0, threadId) != 0) { pRes->code = TSDB_CODE_QRY_IN_EXEC; diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index cd28bb0852cab5805c3e40ee01aac0e1d0b9fa32..3e6867cbc57f0af9958afb66e27ffafebe89609d 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -4536,13 +4536,13 @@ void *superQueryProcess(void *sarg) { } selectAndGetResult(winfo->taos, g_queryInfo.superQueryInfo.sql[i], tmpFile); int64_t t2 = taosGetTimestampUs(); - printf("=[taosc] thread[%"PRIu64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); + printf("=[taosc] thread[%"PRId64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); } else { #ifdef TD_LOWA_CURL int64_t t1 = taosGetTimestampUs(); int retCode = curlProceSql(g_queryInfo.host, g_queryInfo.port, g_queryInfo.superQueryInfo.sql[i], winfo->curl_handle); int64_t t2 = taosGetTimestampUs(); - printf("=[restful] thread[%"PRIu64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); + printf("=[restful] thread[%"PRId64"] complete one sql, Spent %f s\n", taosGetSelfPthreadId(), (t2 - t1)/1000000.0); if (0 != retCode) { printf("====curl return fail, threadID[%d]\n", winfo->threadID); @@ -4552,7 +4552,7 @@ void *superQueryProcess(void *sarg) { } } et = taosGetTimestampMs(); - printf("==thread[%"PRIu64"] complete all sqls to specify tables once queries duration:%.6fs\n\n", taosGetSelfPthreadId(), (double)(et - st)/1000.0); + printf("==thread[%"PRId64"] complete all sqls to specify tables once queries duration:%.6fs\n\n", taosGetSelfPthreadId(), (double)(et - st)/1000.0); } return NULL; } @@ -4601,7 +4601,7 @@ void *subQueryProcess(void *sarg) { } } et = taosGetTimestampMs(); - printf("####thread[%"PRIu64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n", taosGetSelfPthreadId(), winfo->start_table_id, winfo->end_table_id, (double)(et - st)/1000.0); + printf("####thread[%"PRId64"] complete all sqls to allocate all sub-tables[%d - %d] once queries duration:%.4fs\n\n", taosGetSelfPthreadId(), winfo->start_table_id, winfo->end_table_id, (double)(et - st)/1000.0); } return NULL; } diff --git a/src/os/src/darwin/darwinSemphone.c b/src/os/src/darwin/darwinSemphone.c index fa3d364db79dc08dd11fa439c3067835662f7c6a..5bb926732a99a1c2094366624b2a0577c85528d2 100644 --- a/src/os/src/darwin/darwinSemphone.c +++ b/src/os/src/darwin/darwinSemphone.c @@ -32,6 +32,7 @@ #include #include #include +#include static pthread_t sem_thread; static pthread_once_t sem_once; @@ -288,7 +289,9 @@ bool taosCheckPthreadValid(pthread_t thread) { } int64_t taosGetSelfPthreadId() { - return (int64_t)pthread_self(); + uint64_t id; + pthread_threadid_np(0, &id); + return (int64_t) id; } int64_t taosGetPthreadId(pthread_t thread) { diff --git a/src/os/src/detail/osSemphone.c b/src/os/src/detail/osSemphone.c index 1d05ce20a5af51b8e941b0a92d2aea0a04b94882..ec02c65fd645002aaf42243e864584c747b8501a 100644 --- a/src/os/src/detail/osSemphone.c +++ b/src/os/src/detail/osSemphone.c @@ -13,6 +13,8 @@ * along with this program. If not, see . */ +#include + #define _DEFAULT_SOURCE #include "os.h" @@ -31,7 +33,14 @@ int tsem_wait(tsem_t* sem) { #ifndef TAOS_OS_FUNC_SEMPHONE_PTHREAD bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; } -int64_t taosGetSelfPthreadId() { return (int64_t)pthread_self(); } + +int64_t taosGetSelfPthreadId() { + static __thread int id = 0; + if (id != 0) return id; + id = syscall(SYS_gettid); + return id; +} + int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; } void taosResetPthread(pthread_t *thread) { *thread = 0; } bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; } diff --git a/src/os/src/windows/wSemphone.c b/src/os/src/windows/wSemphone.c index 0bc760b35e9016f63a8cd40e1035891cf36e27ae..a3f0367ee1179f74769c8883afe5ee47237ac32b 100644 --- a/src/os/src/windows/wSemphone.c +++ b/src/os/src/windows/wSemphone.c @@ -20,6 +20,7 @@ #include "ttimer.h" #include "tulog.h" #include "tutil.h" +#include bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; } @@ -33,7 +34,9 @@ int64_t taosGetPthreadId(pthread_t thread) { #endif } -int64_t taosGetSelfPthreadId() { return taosGetPthreadId(pthread_self()); } +int64_t taosGetSelfPthreadId() { + return GetCurrentThreadId(); +} bool taosComparePthread(pthread_t first, pthread_t second) { return first.p == second.p; @@ -55,4 +58,4 @@ int32_t taosGetCurrentAPPName(char *name, int32_t* len) { } return 0; -} \ No newline at end of file +} diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 3162ab2e4cbabc2a1ce9ed863589e3be0e92f75f..73177f90e8ee30f3435c0ce011b699f441f79964 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -181,8 +181,8 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { return; } pThreadObj->stop = true; - if (taosComparePthread(thread, pthread_self())) { - pthread_detach(pthread_self()); + if (taosComparePthread(thread, taosGetSelfPthreadId())) { + pthread_detach(taosGetSelfPthreadId()); return; } pthread_join(thread, NULL); @@ -207,8 +207,8 @@ void taosStopTcpServer(void *handle) { #endif } if (taosCheckPthreadValid(pServerObj->thread)) { - if (taosComparePthread(pServerObj->thread, pthread_self())) { - pthread_detach(pthread_self()); + if (taosComparePthread(pServerObj->thread, taosGetSelfPthreadId())) { + pthread_detach(taosGetSelfPthreadId()); } else { pthread_join(pServerObj->thread, NULL); } diff --git a/src/sync/src/syncTcp.c b/src/sync/src/syncTcp.c index 3ad9e9bba01eb861c48fa121b154af3e7838dda0..bef558f41290a9d55569eff99c6931f2b8f37f73 100644 --- a/src/sync/src/syncTcp.c +++ b/src/sync/src/syncTcp.c @@ -327,8 +327,8 @@ static void syncStopPoolThread(SThreadObj *pThread) { return; } pThread->stop = true; - if (taosComparePthread(thread, pthread_self())) { - pthread_detach(pthread_self()); + if (taosComparePthread(thread, taosGetSelfPthreadId())) { + pthread_detach(taosGetSelfPthreadId()); return; } pthread_join(thread, NULL); diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 9770da49acf70fdc339ee5b6497ac213602e3f76..448bb3ecd1bfa8ef17bd7c87a464c095e1093d6d 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -379,7 +379,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); len += sprintf(buffer + len, "%s", flags); @@ -465,7 +465,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); len += sprintf(buffer + len, "%s", flags); diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 56f2322a7bd1e0778e2d52667663b3baf5c08c1f..c6d49dfb3d8242bdf697b3212fde479f01f8bcd9 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -248,7 +248,7 @@ void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { gettimeofday(&timeSecs, NULL); curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%08" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); va_start(argpointer, format); len += vsnprintf(buffer + len, MAX_NOTE_LINE_SIZE - len, format, argpointer);