Update tgeosctx.c

This commit is contained in:
Cary Xu 2024-08-25 19:56:47 +08:00 committed by GitHub
parent c97f01a023
commit b456d6cfcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 6 deletions

View File

@ -19,7 +19,6 @@
static threadlocal TdThreadKey tlGeosCtxKey = 0; static threadlocal TdThreadKey tlGeosCtxKey = 0;
static threadlocal SGeosContext tlGeosCtxObj = {0}; static threadlocal SGeosContext tlGeosCtxObj = {0};
static threadlocal SGeosContext *tlGeosCtx = NULL;
static void destroyThreadLocalGeosCtx(void *param) { static void destroyThreadLocalGeosCtx(void *param) {
SGeosContext *tlGeosCtx = &tlGeosCtxObj; 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) { int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) {
if (tlGeosCtx) { if ((*ppCtx = taosThreadGetSpecific(tlGeosCtxKey))) {
*ppCtx = tlGeosCtx;
return 0; return 0;
} }
@ -72,8 +70,13 @@ int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) {
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
} }
tlGeosCtx = &tlGeosCtxObj; if (!(*ppCtx = taosThreadGetSpecific(tlGeosCtxKey))) {
*ppCtx = tlGeosCtx; if (errno != 0) {
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
} else {
TAOS_CHECK_EXIT(TSDB_CODE_NOT_FOUND);
}
}
_exit: _exit:
if (code != 0) { if (code != 0) {
*ppCtx = NULL; *ppCtx = NULL;
@ -83,5 +86,6 @@ _exit:
} }
const char *getGeosErrMsg(int32_t code) { const char *getGeosErrMsg(int32_t code) {
SGeosContext *tlGeosCtx = taosThreadGetSpecific(tlGeosCtxKey)
return (tlGeosCtx && tlGeosCtx->errMsg[0] != 0) ? tlGeosCtx->errMsg : (code ? tstrerror(code) : ""); return (tlGeosCtx && tlGeosCtx->errMsg[0] != 0) ? tlGeosCtx->errMsg : (code ? tstrerror(code) : "");
} }