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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 using Type = RawPtr<T>; | 1012 using Type = RawPtr<T>; |
1013 }; | 1013 }; |
1014 | 1014 |
1015 template<typename T> | 1015 template<typename T> |
1016 class RawPtrOrMemberTrait<T, true> { | 1016 class RawPtrOrMemberTrait<T, true> { |
1017 STATIC_ONLY(RawPtrOrMemberTrait) | 1017 STATIC_ONLY(RawPtrOrMemberTrait) |
1018 public: | 1018 public: |
1019 using Type = Member<T>; | 1019 using Type = Member<T>; |
1020 }; | 1020 }; |
1021 | 1021 |
1022 // Abstraction for injecting calls to an object's 'dispose()' method | |
1023 // on leaving a stack scope, ensuring earlier release of resources | |
1024 // than waiting until the object is eventually GCed. | |
1025 template<typename T, void (T::*Disposer)() = (&T::dispose)> | |
1026 class ScopedDisposal { | |
1027 STACK_ALLOCATED(); | |
1028 public: | |
1029 ScopedDisposal(T* object) | |
1030 : m_object(object) | |
1031 { | |
1032 } | |
1033 | |
1034 ~ScopedDisposal() | |
1035 { | |
1036 if (m_object) | |
1037 (m_object->*Disposer)(); | |
1038 } | |
1039 | |
1040 void clear() { m_object.clear(); } | |
1041 | |
1042 private: | |
1043 typename RawPtrOrMemberTrait<T>::Type m_object; | |
sof
2016/04/16 05:25:16
This was/is the sole use of this trait.
ftr, I do
| |
1044 }; | |
1045 | |
1046 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep | 1022 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep |
1047 // themselves temporarily alive and cannot rely on there being some | 1023 // themselves temporarily alive and cannot rely on there being some |
1048 // external reference in that interval: | 1024 // external reference in that interval: |
1049 // | 1025 // |
1050 // class Opener { | 1026 // class Opener { |
1051 // public: | 1027 // public: |
1052 // ... | 1028 // ... |
1053 // void open() | 1029 // void open() |
1054 // { | 1030 // { |
1055 // // Retain a self-reference while in an open()ed state: | 1031 // // Retain a self-reference while in an open()ed state: |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1293 // into it. | 1269 // into it. |
1294 // | 1270 // |
1295 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like | 1271 // TODO(sof): remove this hack once wtf/Functional.h can also work with a ty pe like |
1296 // CrossThreadWeakPersistent<>. | 1272 // CrossThreadWeakPersistent<>. |
1297 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); } | 1273 static WeakPtr<T> unwrap(const StorageType& value) { return WeakPtr<T>(WeakR eference<T>::create(value.get())); } |
1298 }; | 1274 }; |
1299 | 1275 |
1300 } // namespace WTF | 1276 } // namespace WTF |
1301 | 1277 |
1302 #endif | 1278 #endif |
OLD | NEW |