From b456d6cfcb0b07a2f2c6806077de049297d8f614 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Sun, 25 Aug 2024 19:56:47 +0800 Subject: [PATCH] Update tgeosctx.c --- source/util/src/tgeosctx.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/util/src/tgeosctx.c b/source/util/src/tgeosctx.c index 9248c8cf58..65c3da2d44 100644 --- a/source/util/src/tgeosctx.c +++ b/source/util/src/tgeosctx.c @@ -19,7 +19,6 @@ static threadlocal TdThreadKey tlGeosCtxKey = 0; static threadlocal SGeosContext tlGeosCtxObj = {0}; -static threadlocal SGeosContext *tlGeosCtx = NULL; static void destroyThreadLocalGeosCtx(void *param) { SGeosContext *tlGeosCtx = &tlGeosCtxObj; @@ -55,11 +54,10 @@ static void destroyThreadLocalGeosCtx(void *param) { } } -SGeosContext *acquireThreadLocalGeosCtx() { return tlGeosCtx; } +SGeosContext *acquireThreadLocalGeosCtx() { return taosThreadGetSpecific(tlGeosCtxKey); } int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) { - if (tlGeosCtx) { - *ppCtx = tlGeosCtx; + if ((*ppCtx = taosThreadGetSpecific(tlGeosCtxKey))) { return 0; } @@ -72,8 +70,13 @@ int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) { TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); } - tlGeosCtx = &tlGeosCtxObj; - *ppCtx = tlGeosCtx; + if (!(*ppCtx = taosThreadGetSpecific(tlGeosCtxKey))) { + if (errno != 0) { + TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); + } else { + TAOS_CHECK_EXIT(TSDB_CODE_NOT_FOUND); + } + } _exit: if (code != 0) { *ppCtx = NULL; @@ -83,5 +86,6 @@ _exit: } const char *getGeosErrMsg(int32_t code) { + SGeosContext *tlGeosCtx = taosThreadGetSpecific(tlGeosCtxKey) return (tlGeosCtx && tlGeosCtx->errMsg[0] != 0) ? tlGeosCtx->errMsg : (code ? tstrerror(code) : ""); }