diff --git a/src/system/runtime_loader/elf_tls.cpp b/src/system/runtime_loader/elf_tls.cpp index f534cecc00..251467c70d 100644 --- a/src/system/runtime_loader/elf_tls.cpp +++ b/src/system/runtime_loader/elf_tls.cpp @@ -12,9 +12,14 @@ #include +#include #include +static const char* const kLockName = "runtime loader tls"; +static mutex sLock = MUTEX_INITIALIZER(kLockName); + + class TLSBlock { public: inline TLSBlock(); @@ -280,6 +285,13 @@ DynamicThreadVector::_ResizeVector(unsigned minimumSize) if (size <= oldSize) return B_OK; + MutexLocker _(sLock); + + // If the size has changed in the meantime, we're done. + oldSize = _Size(); + if (size <= oldSize) + return B_OK; + void* newVector = realloc(*fVector, (size + 1) * sizeof(TLSBlock)); if (newVector == NULL) return B_NO_MEMORY;