#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/threading/thread_local_storage.h"
#include "base/memory/raw_ptr.h"
#include "base/no_destructor.h"
#include "base/threading/simple_thread.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <process.h>
#pragma warning(disable : 4311 4312)
#endif
namespace base {
#if BUILDFLAG(IS_POSIX)
namespace internal {
class ThreadLocalStorageTestInternal { … };
}
#endif
namespace {
const int kInitialTlsValue = …;
const int kFinalTlsValue = …;
const int kNumberDestructorCallRepetitions = …;
void ThreadLocalStorageCleanup(void* value);
ThreadLocalStorage::Slot& TLSSlot() { … }
class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate { … };
void ThreadLocalStorageCleanup(void *value) { … }
#if BUILDFLAG(IS_POSIX)
constexpr intptr_t kDummyValue = …;
constexpr size_t kKeyCount = …;
class UseTLSDuringDestructionRunner { … };
base::ThreadLocalStorage::Slot UseTLSDuringDestructionRunner::slot_;
void* UseTLSTestThreadRun(void* input) { … }
#endif
class TlsDestructionOrderRunner : public DelegateSimpleThread::Delegate { … };
std::vector<int> TlsDestructionOrderRunner::destructor_calls;
class CreateDuringDestructionRunner : public DelegateSimpleThread::Delegate { … };
bool CreateDuringDestructionRunner::second_destructor_called = …;
}
TEST(ThreadLocalStorageTest, Basics) { … }
#if defined(THREAD_SANITIZER)
#define MAYBE_TLSDestructors …
#else
#define MAYBE_TLSDestructors …
#endif
TEST(ThreadLocalStorageTest, MAYBE_TLSDestructors) { … }
TEST(ThreadLocalStorageTest, TLSReclaim) { … }
#if BUILDFLAG(IS_POSIX)
TEST(ThreadLocalStorageTest, UseTLSDuringDestruction) { … }
#endif
TEST(ThreadLocalStorageTest, DestructionOrder) { … }
TEST(ThreadLocalStorageTest, CreateDuringDestruction) { … }
}