Chromium Code Reviews| Index: third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h |
| diff --git a/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h b/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..01a99537e39de9445eb12c530acd2bb0f088833a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef HeapThreadSpecific_h |
| +#define HeapThreadSpecific_h |
| + |
| +#include "platform/heap/Handle.h" |
| +#include "platform/heap/ThreadState.h" |
| +#include "wtf/Functional.h" |
| + |
| +namespace blink { |
| + |
| +// Requests that the thread state clear a persistent handle when the thread |
| +// shuts down. This is intended for use with ThreadSpecific<Persistent<T>>. |
| +// 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
|
| +// raw pointer to that handle. |
| +// |
| +// Example: |
| +// Foo& sharedFoo() |
| +// { |
| +// DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| +// ThreadSpecific<Persistent<Foo>>, threadSpecificFoo, |
| +// new ThreadSpecific<Persistent<Foo>>); |
| +// Persistent<Foo>& fooHandle = *threadSpecificFoo; |
| +// if (!fooHandle) { |
| +// fooHandle = new Foo; |
| +// registerStaticThreadSpecificPersistent(fooHandle); |
| +// } |
|
haraken
2016/04/14 02:36:23
I might prefer introducing Persistent<>::clearOnTh
jbroman
2016/04/14 19:15:28
OK, done.
|
| +// return *fooHandle; |
| +// } |
| +template <typename T> |
| +void registerStaticThreadSpecificPersistent(Persistent<T>& handle) |
| +{ |
| + void (*closure)(Persistent<T>*) = [](Persistent<T>* handle) |
| + { |
| + *handle = nullptr; |
| + }; |
| + ThreadState::current()->registerCleanupHook(WTF::bind(closure, &handle)); |
| +} |
| + |
| +} // namespace blink |
| + |
| +#endif // HeapThreadSpecific_h |