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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/ThreadState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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