// Copyright 2013 The Flutter Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.#include "flutter/fml/thread_local.h"namespacefml{ThreadLocal::ThreadLocal():ThreadLocal(nullptr){}ThreadLocal::ThreadLocal(ThreadLocalDestroyCallbackdestroy):destroy_(destroy){autocallback=reinterpret_cast<void(*)(void*)>(&ThreadLocal::ThreadLocalDestroy);FML_CHECK(pthread_key_create(&_key,callback)==0);}ThreadLocal::~ThreadLocal(){// This will NOT call the destroy callbacks on thread local values still// active in other threads. Those must be cleared manually. The usage// of this class should be similar to the thread_local keyword but with// with a static storage specifier// Collect the containerdeletereinterpret_cast<Box*>(pthread_getspecific(_key));// Finally, collect the keyFML_CHECK(pthread_key_delete(_key)==0);}ThreadLocal::Box::Box(ThreadLocalDestroyCallbackdestroy,intptr_tvalue):destroy_(destroy),value_(value){}ThreadLocal::Box::~Box()=default;}// namespace fml