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

Unified Diff: third_party/WebKit/Source/platform/heap/Handle.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: unit test 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
Index: third_party/WebKit/Source/platform/heap/Handle.h
diff --git a/third_party/WebKit/Source/platform/heap/Handle.h b/third_party/WebKit/Source/platform/heap/Handle.h
index 2313a77dea445fc3564de6116cd2ced698542b5d..2737d39dd2bea5939200a8fc2d19ca7aa3451f09 100644
--- a/third_party/WebKit/Source/platform/heap/Handle.h
+++ b/third_party/WebKit/Source/platform/heap/Handle.h
@@ -330,6 +330,33 @@ public:
Parent::operator=(other);
return *this;
}
+
+ // Requests that the thread state clear this 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 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;
+ // fooHandle.clearOnThreadShutdown();
+ // }
+ // return *fooHandle;
+ // }
+ void clearOnThreadShutdown()
+ {
+ void (*closure)(Persistent<T>*) = [](Persistent<T>* handle)
+ {
+ *handle = nullptr;
+ };
+ ThreadState::current()->registerCleanupHook(WTF::bind(closure, this));
+ }
};
// WeakPersistent is a way to create a weak pointer from an off-heap object

Powered by Google App Engine
This is Rietveld 408576698