Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #ifndef HeapThreadSpecific_h | |
| 6 #define HeapThreadSpecific_h | |
| 7 | |
| 8 #include "platform/heap/Handle.h" | |
| 9 #include "platform/heap/ThreadState.h" | |
| 10 #include "wtf/Functional.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 // Requests that the thread state clear a persistent handle when the thread | |
| 15 // shuts down. This is intended for use with ThreadSpecific<Persistent<T>>. | |
| 16 // It's important that the Persistent<T> exist until then, because this takes a | |
|
haraken
2016/04/14 02:36:23
exist => exists
I'm okay with putting the assumpt
xlai (Olivia)
2016/04/14 16:04:46
Pardon me for popping a question here:
The reason
jbroman
2016/04/14 19:15:28
I believe "exist" is correct here, due to the subj
| |
| 17 // raw pointer to that handle. | |
| 18 // | |
| 19 // Example: | |
| 20 // Foo& sharedFoo() | |
| 21 // { | |
| 22 // DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
| 23 // ThreadSpecific<Persistent<Foo>>, threadSpecificFoo, | |
| 24 // new ThreadSpecific<Persistent<Foo>>); | |
| 25 // Persistent<Foo>& fooHandle = *threadSpecificFoo; | |
| 26 // if (!fooHandle) { | |
| 27 // fooHandle = new Foo; | |
| 28 // registerStaticThreadSpecificPersistent(fooHandle); | |
| 29 // } | |
|
haraken
2016/04/14 02:36:23
I might prefer introducing Persistent<>::clearOnTh
jbroman
2016/04/14 19:15:28
OK, done.
| |
| 30 // return *fooHandle; | |
| 31 // } | |
| 32 template <typename T> | |
| 33 void registerStaticThreadSpecificPersistent(Persistent<T>& handle) | |
| 34 { | |
| 35 void (*closure)(Persistent<T>*) = [](Persistent<T>* handle) | |
| 36 { | |
| 37 *handle = nullptr; | |
| 38 }; | |
| 39 ThreadState::current()->registerCleanupHook(WTF::bind(closure, &handle)); | |
| 40 } | |
| 41 | |
| 42 } // namespace blink | |
| 43 | |
| 44 #endif // HeapThreadSpecific_h | |
| OLD | NEW |