Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( | 201 base::subtle::DeleteHelperInternal<T, void>::DeleteViaSequencedTaskRunner( |
| 202 this, from_here, object); | 202 this, from_here, object); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // A variant on PostTask that releases the given reference counted object | 205 // A variant on PostTask that releases the given reference counted object |
| 206 // (by calling its Release method). This is useful if the object needs to | 206 // (by calling its Release method). This is useful if the object needs to |
| 207 // live until the next run of the MessageLoop, or if the object needs to be | 207 // live until the next run of the MessageLoop, or if the object needs to be |
| 208 // released on a particular thread. | 208 // released on a particular thread. |
| 209 // | 209 // |
| 210 // A common pattern is to manually increment the object's reference count | 210 // A common pattern is to manually increment the object's reference count |
| 211 // (AddRef), issue a ReleaseSoon, then clear the pointer. The reference count | 211 // (AddRef), issue a ReleaseSoon, then clear the pointer. The reference count |
|
maniscalco
2014/05/29 16:40:36
We should also switch the order of ReleaseSoon and
vkuzkokov
2014/05/30 07:19:32
Done.
| |
| 212 // is incremented manually to ensure clearing the pointer does not trigger a | 212 // is incremented manually to ensure clearing the pointer does not trigger a |
| 213 // delete and to account for the upcoming decrement (ReleaseSoon). For | 213 // delete and to account for the upcoming decrement (ReleaseSoon). For |
| 214 // example: | 214 // example: |
| 215 // | 215 // |
| 216 // scoped_refptr<Foo> foo = ... | 216 // scoped_refptr<Foo> foo = ... |
| 217 // foo.AddRef(); | 217 // foo->AddRef(); |
| 218 // message_loop->ReleaseSoon(foo.get()); | 218 // Foo* raw_foo = foo.get(); |
| 219 // foo = NULL; | 219 // foo = NULL; |
|
Mark Mentovai
2014/05/29 20:42:10
If everything is RefCountedThreadSafe, why should
maniscalco
2014/05/29 22:50:31
Here's my understanding. vkuzkokov, correct me if
| |
| 220 // message_loop->ReleaseSoon(raw_foo); | |
| 220 // | 221 // |
| 221 // NOTE: This method may be called on any thread. The object will be | 222 // NOTE: This method may be called on any thread. The object will be |
| 222 // released (and thus possibly deleted) on the thread that executes | 223 // released (and thus possibly deleted) on the thread that executes |
| 223 // MessageLoop::Run(). If this is not the same as the thread that calls | 224 // MessageLoop::Run(). If this is not the same as the thread that calls |
| 224 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from | 225 // PostDelayedTask(FROM_HERE, ), then T MUST inherit from |
| 225 // RefCountedThreadSafe<T>! | 226 // RefCountedThreadSafe<T>! |
| 226 template <class T> | 227 template <class T> |
| 227 void ReleaseSoon(const tracked_objects::Location& from_here, | 228 void ReleaseSoon(const tracked_objects::Location& from_here, |
| 228 const T* object) { | 229 const T* object) { |
| 229 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( | 230 base::subtle::ReleaseHelperInternal<T, void>::ReleaseViaSequencedTaskRunner( |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 | 642 |
| 642 // Do not add any member variables to MessageLoopForIO! This is important b/c | 643 // Do not add any member variables to MessageLoopForIO! This is important b/c |
| 643 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra | 644 // MessageLoopForIO is often allocated via MessageLoop(TYPE_IO). Any extra |
| 644 // data that you need should be stored on the MessageLoop's pump_ instance. | 645 // data that you need should be stored on the MessageLoop's pump_ instance. |
| 645 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), | 646 COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO), |
| 646 MessageLoopForIO_should_not_have_extra_member_variables); | 647 MessageLoopForIO_should_not_have_extra_member_variables); |
| 647 | 648 |
| 648 } // namespace base | 649 } // namespace base |
| 649 | 650 |
| 650 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ | 651 #endif // BASE_MESSAGE_LOOP_MESSAGE_LOOP_H_ |
| OLD | NEW |