| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 Persistent(std::nullptr_t) : Parent(nullptr) { } | 281 Persistent(std::nullptr_t) : Parent(nullptr) { } |
| 282 Persistent(T* raw) : Parent(raw) { } | 282 Persistent(T* raw) : Parent(raw) { } |
| 283 Persistent(T& raw) : Parent(raw) { } | 283 Persistent(T& raw) : Parent(raw) { } |
| 284 Persistent(const Persistent& other) : Parent(other) { } | 284 Persistent(const Persistent& other) : Parent(other) { } |
| 285 template<typename U> | 285 template<typename U> |
| 286 Persistent(const Persistent<U>& other) : Parent(other) { } | 286 Persistent(const Persistent<U>& other) : Parent(other) { } |
| 287 template<typename U> | 287 template<typename U> |
| 288 Persistent(const Member<U>& other) : Parent(other) { } | 288 Persistent(const Member<U>& other) : Parent(other) { } |
| 289 template<typename U> | 289 template<typename U> |
| 290 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } | 290 Persistent(const RawPtr<U>& other) : Parent(other.get()) { } |
| 291 |
| 292 template<typename U> |
| 293 Persistent& operator=(U* other) |
| 294 { |
| 295 Parent::operator=(other); |
| 296 return *this; |
| 297 } |
| 298 |
| 299 Persistent& operator=(std::nullptr_t) |
| 300 { |
| 301 Parent::operator=(nullptr); |
| 302 return *this; |
| 303 } |
| 304 |
| 305 Persistent& operator=(const Persistent& other) |
| 306 { |
| 307 Parent::operator=(other); |
| 308 return *this; |
| 309 } |
| 310 |
| 311 template<typename U> |
| 312 Persistent& operator=(const Persistent<U>& other) |
| 313 { |
| 314 Parent::operator=(other); |
| 315 return *this; |
| 316 } |
| 317 |
| 318 template<typename U> |
| 319 Persistent& operator=(const Member<U>& other) |
| 320 { |
| 321 Parent::operator=(other); |
| 322 return *this; |
| 323 } |
| 324 |
| 325 template<typename U> |
| 326 Persistent& operator=(const RawPtr<U>& other) |
| 327 { |
| 328 Parent::operator=(other); |
| 329 return *this; |
| 330 } |
| 291 }; | 331 }; |
| 292 | 332 |
| 293 // WeakPersistent is a way to create a weak pointer from an off-heap object | 333 // WeakPersistent is a way to create a weak pointer from an off-heap object |
| 294 // to an on-heap object. The m_raw is automatically cleared when the pointee | 334 // to an on-heap object. The m_raw is automatically cleared when the pointee |
| 295 // gets collected. | 335 // gets collected. |
| 296 // | 336 // |
| 297 // We have to construct and destruct WeakPersistent in the same thread. | 337 // We have to construct and destruct WeakPersistent in the same thread. |
| 298 // | 338 // |
| 299 // Note that collections of WeakPersistents are not supported. Use a persistent | 339 // Note that collections of WeakPersistents are not supported. Use a persistent |
| 300 // collection of WeakMembers instead. | 340 // collection of WeakMembers instead. |
| 301 // | 341 // |
| 302 // HashSet<WeakPersistent<T>> m_set; // wrong | 342 // HashSet<WeakPersistent<T>> m_set; // wrong |
| 303 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct | 343 // PersistentHeapHashSet<WeakMember<T>> m_set; // correct |
| 304 template<typename T> | 344 template<typename T> |
| 305 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin
gleThreadPersistentConfiguration> { | 345 class WeakPersistent : public PersistentBase<T, WeakPersistentConfiguration, Sin
gleThreadPersistentConfiguration> { |
| 306 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten
tConfiguration> Parent; | 346 typedef PersistentBase<T, WeakPersistentConfiguration, SingleThreadPersisten
tConfiguration> Parent; |
| 307 public: | 347 public: |
| 308 WeakPersistent() : Parent() { } | 348 WeakPersistent() : Parent() { } |
| 309 WeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 349 WeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 310 WeakPersistent(T* raw) : Parent(raw) { } | 350 WeakPersistent(T* raw) : Parent(raw) { } |
| 311 WeakPersistent(T& raw) : Parent(raw) { } | 351 WeakPersistent(T& raw) : Parent(raw) { } |
| 312 WeakPersistent(const WeakPersistent& other) : Parent(other) { } | 352 WeakPersistent(const WeakPersistent& other) : Parent(other) { } |
| 313 template<typename U> | 353 template<typename U> |
| 314 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { } | 354 WeakPersistent(const WeakPersistent<U>& other) : Parent(other) { } |
| 315 template<typename U> | 355 template<typename U> |
| 316 WeakPersistent(const Member<U>& other) : Parent(other) { } | 356 WeakPersistent(const Member<U>& other) : Parent(other) { } |
| 317 template<typename U> | 357 template<typename U> |
| 318 WeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | 358 WeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
| 359 |
| 360 template<typename U> |
| 361 WeakPersistent& operator=(U* other) |
| 362 { |
| 363 Parent::operator=(other); |
| 364 return *this; |
| 365 } |
| 366 |
| 367 WeakPersistent& operator=(std::nullptr_t) |
| 368 { |
| 369 Parent::operator=(nullptr); |
| 370 return *this; |
| 371 } |
| 372 |
| 373 WeakPersistent& operator=(const WeakPersistent& other) |
| 374 { |
| 375 Parent::operator=(other); |
| 376 return *this; |
| 377 } |
| 378 |
| 379 template<typename U> |
| 380 WeakPersistent& operator=(const WeakPersistent<U>& other) |
| 381 { |
| 382 Parent::operator=(other); |
| 383 return *this; |
| 384 } |
| 385 |
| 386 template<typename U> |
| 387 WeakPersistent& operator=(const Member<U>& other) |
| 388 { |
| 389 Parent::operator=(other); |
| 390 return *this; |
| 391 } |
| 392 |
| 393 template<typename U> |
| 394 WeakPersistent& operator=(const RawPtr<U>& other) |
| 395 { |
| 396 Parent::operator=(other); |
| 397 return *this; |
| 398 } |
| 319 }; | 399 }; |
| 320 | 400 |
| 321 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread | 401 // Unlike Persistent, we can destruct a CrossThreadPersistent in a thread |
| 322 // different from the construction thread. | 402 // different from the construction thread. |
| 323 template<typename T> | 403 template<typename T> |
| 324 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur
ation, CrossThreadPersistentConfiguration> { | 404 class CrossThreadPersistent : public PersistentBase<T, NonWeakPersistentConfigur
ation, CrossThreadPersistentConfiguration> { |
| 325 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist
entConfiguration> Parent; | 405 typedef PersistentBase<T, NonWeakPersistentConfiguration, CrossThreadPersist
entConfiguration> Parent; |
| 326 public: | 406 public: |
| 327 CrossThreadPersistent() : Parent() { } | 407 CrossThreadPersistent() : Parent() { } |
| 328 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } | 408 CrossThreadPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 329 CrossThreadPersistent(T* raw) : Parent(raw) { } | 409 CrossThreadPersistent(T* raw) : Parent(raw) { } |
| 330 CrossThreadPersistent(T& raw) : Parent(raw) { } | 410 CrossThreadPersistent(T& raw) : Parent(raw) { } |
| 331 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) {
} | 411 CrossThreadPersistent(const CrossThreadPersistent& other) : Parent(other) {
} |
| 332 template<typename U> | 412 template<typename U> |
| 333 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other)
{ } | 413 CrossThreadPersistent(const CrossThreadPersistent<U>& other) : Parent(other)
{ } |
| 334 template<typename U> | 414 template<typename U> |
| 335 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } | 415 CrossThreadPersistent(const Member<U>& other) : Parent(other) { } |
| 336 template<typename U> | 416 template<typename U> |
| 337 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | 417 CrossThreadPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
| 418 |
| 419 template<typename U> |
| 420 CrossThreadPersistent& operator=(U* other) |
| 421 { |
| 422 Parent::operator=(other); |
| 423 return *this; |
| 424 } |
| 425 |
| 426 CrossThreadPersistent& operator=(std::nullptr_t) |
| 427 { |
| 428 Parent::operator=(nullptr); |
| 429 return *this; |
| 430 } |
| 431 |
| 432 CrossThreadPersistent& operator=(const CrossThreadPersistent& other) |
| 433 { |
| 434 Parent::operator=(other); |
| 435 return *this; |
| 436 } |
| 437 |
| 438 template<typename U> |
| 439 CrossThreadPersistent& operator=(const CrossThreadPersistent<U>& other) |
| 440 { |
| 441 Parent::operator=(other); |
| 442 return *this; |
| 443 } |
| 444 |
| 445 template<typename U> |
| 446 CrossThreadPersistent& operator=(const Member<U>& other) |
| 447 { |
| 448 Parent::operator=(other); |
| 449 return *this; |
| 450 } |
| 451 |
| 452 template<typename U> |
| 453 CrossThreadPersistent& operator=(const RawPtr<U>& other) |
| 454 { |
| 455 Parent::operator=(other); |
| 456 return *this; |
| 457 } |
| 338 }; | 458 }; |
| 339 | 459 |
| 340 // Combines the behavior of CrossThreadPersistent and WeakPersistent. | 460 // Combines the behavior of CrossThreadPersistent and WeakPersistent. |
| 341 template<typename T> | 461 template<typename T> |
| 342 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { | 462 class CrossThreadWeakPersistent : public PersistentBase<T, WeakPersistentConfigu
ration, CrossThreadPersistentConfiguration> { |
| 343 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; | 463 typedef PersistentBase<T, WeakPersistentConfiguration, CrossThreadPersistent
Configuration> Parent; |
| 344 public: | 464 public: |
| 345 CrossThreadWeakPersistent() : Parent() { } | 465 CrossThreadWeakPersistent() : Parent() { } |
| 346 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } | 466 CrossThreadWeakPersistent(std::nullptr_t) : Parent(nullptr) { } |
| 347 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } | 467 CrossThreadWeakPersistent(T* raw) : Parent(raw) { } |
| 348 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } | 468 CrossThreadWeakPersistent(T& raw) : Parent(raw) { } |
| 349 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } | 469 CrossThreadWeakPersistent(const CrossThreadWeakPersistent& other) : Parent(o
ther) { } |
| 350 template<typename U> | 470 template<typename U> |
| 351 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren
t(other) { } | 471 CrossThreadWeakPersistent(const CrossThreadWeakPersistent<U>& other) : Paren
t(other) { } |
| 352 template<typename U> | 472 template<typename U> |
| 353 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } | 473 CrossThreadWeakPersistent(const Member<U>& other) : Parent(other) { } |
| 354 template<typename U> | 474 template<typename U> |
| 355 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } | 475 CrossThreadWeakPersistent(const RawPtr<U>& other) : Parent(other.get()) { } |
| 476 |
| 477 template<typename U> |
| 478 CrossThreadWeakPersistent& operator=(U* other) |
| 479 { |
| 480 Parent::operator=(other); |
| 481 return *this; |
| 482 } |
| 483 |
| 484 CrossThreadWeakPersistent& operator=(std::nullptr_t) |
| 485 { |
| 486 Parent::operator=(nullptr); |
| 487 return *this; |
| 488 } |
| 489 |
| 490 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent& other) |
| 491 { |
| 492 Parent::operator=(other); |
| 493 return *this; |
| 494 } |
| 495 |
| 496 template<typename U> |
| 497 CrossThreadWeakPersistent& operator=(const CrossThreadWeakPersistent<U>& oth
er) |
| 498 { |
| 499 Parent::operator=(other); |
| 500 return *this; |
| 501 } |
| 502 |
| 503 template<typename U> |
| 504 CrossThreadWeakPersistent& operator=(const Member<U>& other) |
| 505 { |
| 506 Parent::operator=(other); |
| 507 return *this; |
| 508 } |
| 509 |
| 510 template<typename U> |
| 511 CrossThreadWeakPersistent& operator=(const RawPtr<U>& other) |
| 512 { |
| 513 Parent::operator=(other); |
| 514 return *this; |
| 515 } |
| 356 }; | 516 }; |
| 357 | 517 |
| 358 template<typename Collection> | 518 template<typename Collection> |
| 359 class PersistentHeapCollectionBase : public Collection { | 519 class PersistentHeapCollectionBase : public Collection { |
| 360 // We overload the various new and delete operators with using the WTF Defau
ltAllocator to ensure persistent | 520 // We overload the various new and delete operators with using the WTF Defau
ltAllocator to ensure persistent |
| 361 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in | 521 // heap collections are always allocated off-heap. This allows persistent co
llections to be used in |
| 362 // DEFINE_STATIC_LOCAL et. al. | 522 // DEFINE_STATIC_LOCAL et. al. |
| 363 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); | 523 WTF_USE_ALLOCATOR(PersistentHeapCollectionBase, WTF::DefaultAllocator); |
| 364 public: | 524 public: |
| 365 PersistentHeapCollectionBase() | 525 PersistentHeapCollectionBase() |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. | 1369 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. |
| 1210 static T* unwrap(const StorageType& value) { return value.get(); } | 1370 static T* unwrap(const StorageType& value) { return value.get(); } |
| 1211 }; | 1371 }; |
| 1212 | 1372 |
| 1213 template<typename T> | 1373 template<typename T> |
| 1214 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1374 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
| 1215 | 1375 |
| 1216 } // namespace WTF | 1376 } // namespace WTF |
| 1217 | 1377 |
| 1218 #endif | 1378 #endif |
| OLD | NEW |