1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "content/public/utility/utility_thread.h" 6 7#include "base/lazy_instance.h" 8#include "base/threading/thread_local.h" 9 10namespace content { 11 12// Keep the global UtilityThread in a TLS slot so it is impossible to access 13// incorrectly from the wrong thread. 14static base::LazyInstance<base::ThreadLocalPointer<UtilityThread> >::Leaky 15 lazy_tls = LAZY_INSTANCE_INITIALIZER; 16 17UtilityThread* UtilityThread::Get() { 18 return lazy_tls.Pointer()->Get(); 19} 20 21UtilityThread::UtilityThread() { 22 lazy_tls.Pointer()->Set(this); 23} 24 25UtilityThread::~UtilityThread() { 26 lazy_tls.Pointer()->Set(NULL); 27} 28 29} // namespace content 30 31