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 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 void assign(Self* self) | 1292 void assign(Self* self) |
1293 { | 1293 { |
1294 ASSERT(!m_keepAlive || m_keepAlive.get() == self); | 1294 ASSERT(!m_keepAlive || m_keepAlive.get() == self); |
1295 m_keepAlive = self; | 1295 m_keepAlive = self; |
1296 } | 1296 } |
1297 | 1297 |
1298 GC_PLUGIN_IGNORE("420515") | 1298 GC_PLUGIN_IGNORE("420515") |
1299 Persistent<Self> m_keepAlive; | 1299 Persistent<Self> m_keepAlive; |
1300 }; | 1300 }; |
1301 | 1301 |
| 1302 // Only a very reduced form of weak heap object references can currently be held |
| 1303 // by WTF::Closure<>s. i.e., bound as a 'this' pointer only. |
| 1304 // |
| 1305 // TODO(sof): once wtf/Functional.h is able to work over platform/heap/ types |
| 1306 // (like CrossThreadWeakPersistent<>), drop the restriction on weak persistent |
| 1307 // use by function closures (and rename this ad-hoc type.) |
1302 template<typename T> | 1308 template<typename T> |
1303 class AllowCrossThreadWeakPersistent { | 1309 class CrossThreadWeakPersistentThisPointer { |
1304 STACK_ALLOCATED(); | 1310 STACK_ALLOCATED(); |
1305 public: | 1311 public: |
1306 explicit AllowCrossThreadWeakPersistent(T* value) : m_value(value) { } | 1312 explicit CrossThreadWeakPersistentThisPointer(T* value) : m_value(value) { } |
1307 CrossThreadWeakPersistent<T> value() const { return m_value; } | 1313 CrossThreadWeakPersistent<T> value() const { return m_value; } |
1308 private: | 1314 private: |
1309 CrossThreadWeakPersistent<T> m_value; | 1315 CrossThreadWeakPersistent<T> m_value; |
1310 }; | 1316 }; |
1311 | 1317 |
1312 // LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the current scope | 1318 // LEAK_SANITIZER_DISABLED_SCOPE: all allocations made in the current scope |
1313 // will be exempted from LSan consideration. | 1319 // will be exempted from LSan consideration. |
1314 // | 1320 // |
1315 // TODO(sof): move this to wtf/LeakAnnotations.h (LeakSanitizer.h?) once | 1321 // TODO(sof): move this to wtf/LeakAnnotations.h (LeakSanitizer.h?) once |
1316 // wtf/ can freely call upon Oilpan functionality. | 1322 // wtf/ can freely call upon Oilpan functionality. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { | 1568 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, blink::IsGa
rbageCollectedType<T>::value> { |
1563 static_assert(sizeof(T), "T must be fully defined"); | 1569 static_assert(sizeof(T), "T must be fully defined"); |
1564 }; | 1570 }; |
1565 | 1571 |
1566 template<typename T> | 1572 template<typename T> |
1567 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { | 1573 struct ParamStorageTraits<RawPtr<T>> : public PointerParamStorageTraits<T*, blin
k::IsGarbageCollectedType<T>::value> { |
1568 static_assert(sizeof(T), "T must be fully defined"); | 1574 static_assert(sizeof(T), "T must be fully defined"); |
1569 }; | 1575 }; |
1570 | 1576 |
1571 template<typename T> | 1577 template<typename T> |
1572 struct ParamStorageTraits<blink::AllowCrossThreadWeakPersistent<T>> { | 1578 struct ParamStorageTraits<blink::CrossThreadWeakPersistentThisPointer<T>> { |
1573 static_assert(sizeof(T), "T must be fully defined"); | 1579 static_assert(sizeof(T), "T must be fully defined"); |
1574 using StorageType = blink::CrossThreadWeakPersistent<T>; | 1580 using StorageType = blink::CrossThreadWeakPersistent<T>; |
1575 | 1581 |
1576 static StorageType wrap(const blink::AllowCrossThreadWeakPersistent<T>& valu
e) { return value.value(); } | 1582 static StorageType wrap(const blink::CrossThreadWeakPersistentThisPointer<T>
& value) { return value.value(); } |
1577 | 1583 |
1578 // Currently assume that the call sites of this unwrap() account for cleared
weak references also. | 1584 // WTF::FunctionWrapper<> handles WeakPtr<>, so recast this weak persistent |
1579 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C
rossThread)WeakPersistent. | 1585 // into it. |
1580 static T* unwrap(const StorageType& value) { return value.get(); } | 1586 // |
| 1587 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty
pe like |
| 1588 // CrossThreadWeakPersistent<>. |
| 1589 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR
eference<T>::create(value.get())); } |
1581 }; | 1590 }; |
1582 | 1591 |
1583 template<typename T> | 1592 template<typename T> |
1584 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; | 1593 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; |
1585 | 1594 |
1586 } // namespace WTF | 1595 } // namespace WTF |
1587 | 1596 |
1588 #endif | 1597 #endif |
OLD | NEW |