Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2638)

Unified Diff: docs/design/threading.md

Issue 2944313004: Correct threading documentation example. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: docs/design/threading.md
diff --git a/docs/design/threading.md b/docs/design/threading.md
index 105891cfab01b4c9e07c8fe9e78f826b46549d55..9faa6d0cb9e2cee83781f296a72e587d5818a152 100644
--- a/docs/design/threading.md
+++ b/docs/design/threading.md
@@ -19,7 +19,7 @@ rather than make new ones. We already have a lot of threads that are difficult
to keep track of. Each thread has a `MessageLoop` (see
[`base/message_loop/message_loop.h`](https://cs.chromium.org/chromium/src/base/message_loop/message_loop.h)
that processes messages for that thread. You can get the message loop for a
-thread using the `Thread.message_loop()` function. More details about
+thread using the `Thread.message_loop()` function. More details about
`MessageLoop` can be found in
[Anatomy of Chromium MessageLoop](https://docs.google.com/document/d/1_pJUHO3f3VyRSQjEhKVvUU7NzCyuTCQshZvbWeQiCXU/view#).
@@ -242,18 +242,22 @@ raw pointer with `make_scoped_refptr()`:
public:
void DoSomething() {
scoped_refptr<SomeParamObject> param(new SomeParamObject);
- thread_->message_loop()->PostTask(FROM_HERE
- base::Bind(&MyObject::DoSomethingOnAnotherThread, this, param));
+
+ // Moving |param| prevents an extra AddRef()/Release() pair.
lazyboy 2017/06/23 20:43:27 Nice, I think you should separate out this std::mo
karandeepb 2017/06/23 22:48:46 Done. Yeah it doesn't compile.
+ thread_->message_loop()->PostTask(FROM_HERE,
+ base::Bind(&MyObject::DoSomethingOnAnotherThread, this,
+ base::RetainedRef(std::move(param))));
}
void DoSomething2() {
SomeParamObject* param = new SomeParamObject;
- thread_->message_loop()->PostTask(FROM_HERE
+ thread_->message_loop()->PostTask(FROM_HERE,
base::Bind(&MyObject::DoSomethingOnAnotherThread, this,
- make_scoped_refptr(param)));
+ base::RetainedRef(make_scoped_refptr(param))));
}
- // Note how this takes a raw pointer. The important part is that
- // base::Bind() was passed a scoped_refptr; using a scoped_refptr
- // here would result in an extra AddRef()/Release() pair.
+
+ // Note how this takes a raw pointer. The important part is that using
lazyboy 2017/06/23 20:43:27 The comment here before was emphasizing that inste
karandeepb 2017/06/23 22:48:46 Done.
+ // base::RetainedRef allows passing a raw pointer when the callback is run
+ // preventing an extra AddRef()/Release() pair.
void DoSomethingOnAnotherThread(SomeParamObject* param) {
...
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698