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