Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapThreadSpecific.h

Issue 1881933005: Oilpan: Add ThreadState cleanup callbacks for static thread-specific persistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/ThreadState.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698