| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 Parent::operator=(other); | 323 Parent::operator=(other); |
| 324 return *this; | 324 return *this; |
| 325 } | 325 } |
| 326 | 326 |
| 327 template<typename U> | 327 template<typename U> |
| 328 Persistent& operator=(const Member<U>& other) | 328 Persistent& operator=(const Member<U>& other) |
| 329 { | 329 { |
| 330 Parent::operator=(other); | 330 Parent::operator=(other); |
| 331 return *this; | 331 return *this; |
| 332 } | 332 } |
| 333 |
| 334 // Requests that the thread state clear this handle when the thread shuts |
| 335 // down. This is intended for use with ThreadSpecific<Persistent<T>>. |
| 336 // It's important that the Persistent<T> exist until then, because this |
| 337 // takes a raw pointer to that handle. |
| 338 // |
| 339 // Example: |
| 340 // Foo& sharedFoo() |
| 341 // { |
| 342 // DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 343 // ThreadSpecific<Persistent<Foo>>, threadSpecificFoo, |
| 344 // new ThreadSpecific<Persistent<Foo>>); |
| 345 // Persistent<Foo>& fooHandle = *threadSpecificFoo; |
| 346 // if (!fooHandle) { |
| 347 // fooHandle = new Foo; |
| 348 // fooHandle.clearOnThreadShutdown(); |
| 349 // } |
| 350 // return *fooHandle; |
| 351 // } |
| 352 void clearOnThreadShutdown() |
| 353 { |
| 354 void (*closure)(Persistent<T>*) = [](Persistent<T>* handle) |
| 355 { |
| 356 *handle = nullptr; |
| 357 }; |
| 358 ThreadState::current()->registerCleanupHook(WTF::bind(closure, this)); |
| 359 } |
| 333 }; | 360 }; |
| 334 | 361 |
| 335 // WeakPersistent is a way to create a weak pointer from an off-heap object | 362 // WeakPersistent is a way to create a weak pointer from an off-heap object |
| 336 // to an on-heap object. The m_raw is automatically cleared when the pointee | 363 // to an on-heap object. The m_raw is automatically cleared when the pointee |
| 337 // gets collected. | 364 // gets collected. |
| 338 // | 365 // |
| 339 // We have to construct and destruct WeakPersistent in the same thread. | 366 // We have to construct and destruct WeakPersistent in the same thread. |
| 340 // | 367 // |
| 341 // Note that collections of WeakPersistents are not supported. Use a persistent | 368 // Note that collections of WeakPersistents are not supported. Use a persistent |
| 342 // collection of WeakMembers instead. | 369 // collection of WeakMembers instead. |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 // into it. | 1227 // into it. |
| 1201 // | 1228 // |
| 1202 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like | 1229 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like |
| 1203 // CrossThreadWeakPersistent<>. | 1230 // CrossThreadWeakPersistent<>. |
| 1204 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } | 1231 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } |
| 1205 }; | 1232 }; |
| 1206 | 1233 |
| 1207 } // namespace WTF | 1234 } // namespace WTF |
| 1208 | 1235 |
| 1209 #endif | 1236 #endif |
| OLD | NEW |