Merge pull request #27556 from taosdata/fix/TD-31163-3.0

fix: geos thread key init
This commit is contained in:
Hongze Cheng 2024-08-30 16:27:41 +08:00 committed by GitHub
commit 4b054e4ebd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 1 deletions

View File

@ -72,11 +72,23 @@ int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) {
}
int32_t code = 0, lino = 0;
if (atomic_val_compare_exchange_8(&tlGeosCtxKeyInited, 0, 1) == 0) {
int8_t old;
int32_t nLoops = 0;
while (1) {
old = atomic_val_compare_exchange_8(&tlGeosCtxKeyInited, 0, 2);
if (old != 2) break;
if (++nLoops > 1000) {
(void)sched_yield();
nLoops = 0;
}
}
if (old == 0) {
if ((taosThreadKeyCreate(&tlGeosCtxKey, destroyThreadLocalGeosCtx)) != 0) {
atomic_store_8(&tlGeosCtxKeyInited, 0);
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
}
atomic_store_8(&tlGeosCtxKeyInited, 1);
}
SGeosContext *tlGeosCtxObj = (SGeosContext *)taosMemoryCalloc(1, sizeof(SGeosContext));