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

Issue 6052006: Proof of concept for tr1-based Task replacement. (Closed)

Created:
10 years ago by awong
Modified:
9 years, 7 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, darin-cc_chromium.org, brettw-cc_chromium.org, Paweł Hajdan Jr., rdsmith+dwatch_chromium.org
Visibility:
Public.

Description

Proof of concept for tr1-based Task replacement. BUG= TEST=

Patch Set 1 #

Patch Set 2 : HostResolverImpl ported and unittest passing. #

Patch Set 3 : 80-chars #

Patch Set 4 : Examples of replacing CreateFunctor, ScopedRMF, CompletionCallback #

Total comments: 31
Unified diffs Side-by-side diffs Delta from patch set Stats (+497 lines, -52 lines) Patch
M base/base.gypi View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
A base/closure.h View 1 2 3 1 chunk +338 lines, -0 lines 31 comments Download
M base/message_loop.h View 1 2 3 2 chunks +8 lines, -0 lines 0 comments Download
M base/message_loop.cc View 1 2 3 2 chunks +35 lines, -0 lines 0 comments Download
M base/task.cc View 1 2 3 1 chunk +6 lines, -0 lines 0 comments Download
M base/worker_pool.h View 1 2 2 chunks +29 lines, -0 lines 0 comments Download
M chrome/browser/download/download_manager_unittest.cc View 1 2 3 4 chunks +12 lines, -8 lines 0 comments Download
M net/base/host_resolver_impl.cc View 1 4 chunks +11 lines, -13 lines 0 comments Download
M net/socket/client_socket_pool_base.h View 1 2 3 9 chunks +30 lines, -11 lines 0 comments Download
M net/socket/client_socket_pool_base.cc View 1 2 3 8 chunks +27 lines, -20 lines 0 comments Download

Messages

Total messages: 11 (0 generated)
awong
Surprise Holiday Present: proof of concept implementation of redoing Task using tr1. There's some ugly ...
10 years ago (2010-12-24 03:39:16 UTC) #1
awong
Added some examples of replacing CreateFunctor, CompletionCallback, and ScopedRunnableMethodFactory. This should be pretty complete coverage ...
9 years, 12 months ago (2010-12-28 23:24:02 UTC) #2
brettw
http://codereview.chromium.org/6052006/diff/7001/base/closure.h File base/closure.h (right): http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode1 base/closure.h:1: // Copyright (c) 2009 The Chromium Authors. All rights ...
9 years, 11 months ago (2011-01-04 19:12:17 UTC) #3
brettw
http://codereview.chromium.org/6052006/diff/7001/base/closure.h File base/closure.h (right): http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode199 base/closure.h:199: : state_(new ClosureState(new tracked_objects::Tracked())) { Actually NewRunnableMethod of course ...
9 years, 11 months ago (2011-01-04 19:14:57 UTC) #4
awong
Thanks for the review! Especially thanks for looking over the memory allocation/copy semantics. Address most ...
9 years, 11 months ago (2011-01-04 20:57:12 UTC) #5
willchan no longer on Chromium
http://codereview.chromium.org/6052006/diff/7001/base/closure.h File base/closure.h (right): http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode217 base/closure.h:217: Closure(Sig f, A1 a1, A2 a2, A3 a3, A4 ...
9 years, 11 months ago (2011-01-04 21:09:22 UTC) #6
awong
On 2011/01/04 21:09:22, willchan wrote: > http://codereview.chromium.org/6052006/diff/7001/base/closure.h > File base/closure.h (right): > > http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode217 > ...
9 years, 11 months ago (2011-01-04 21:44:45 UTC) #7
willchan no longer on Chromium
On 2011/01/04 21:44:45, awong wrote: > On 2011/01/04 21:09:22, willchan wrote: > > http://codereview.chromium.org/6052006/diff/7001/base/closure.h > ...
9 years, 11 months ago (2011-01-04 21:56:22 UTC) #8
awong
On 2011/01/04 21:56:22, willchan wrote: > On 2011/01/04 21:44:45, awong wrote: > > On 2011/01/04 ...
9 years, 11 months ago (2011-01-04 22:14:59 UTC) #9
willchan no longer on Chromium
http://codereview.chromium.org/6052006/diff/7001/base/closure.h File base/closure.h (right): http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode35 base/closure.h:35: release_thunk_(); Why? We don't do this for Tasks. http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode43 ...
9 years, 11 months ago (2011-01-04 22:27:22 UTC) #10
awong
9 years, 11 months ago (2011-01-04 22:37:35 UTC) #11
On Tue, Jan 4, 2011 at 2:27 PM, <willchan@chromium.org> wrote:

>
> http://codereview.chromium.org/6052006/diff/7001/base/closure.h
> File base/closure.h (right):
>
> http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode35
> base/closure.h:35: release_thunk_();
> Why?  We don't do this for Tasks.
>
> http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode43
> base/closure.h:43: scoped_ptr<tracked_objects::Tracked> tracked_;
> I'm not sure, but this might be a design flaw.  ClosureState is shared.
> tracked_objects::Tracked is designed to be used for a single task run on
> an executor (MessageLoop or WorkerPool or what not).
>
> So, if you intend a Closure to be allowed to be "permanent", then it
> needs to be postable multiple times.  This means each time it's posted,
> it needs a new tracked_objects::Tracked.
>
> Really, that we make Task inherit from tracked_objects::Tracked seems
> like a design flaw.  I think that tracked_objects::Tracked should be a
> sibling object of the Task, contained within PendingTask.  Then this
> would work properly.


This is an interesting point...Tracked does 2 things currently.
  (1) Track the "post" location (though it calls it the BirthPlace).
  (2) Track the creation time.

If we disassociate these two parts, we can avoid this shared state.

I agree that Task inheriting from Tracked feels odd.  It does feel more of
something that belongs to the MesasgeLoop rather than the Task.

http://codereview.chromium.org/6052006/diff/7001/base/closure.h#newcode199
> base/closure.h:199: : state_(new ClosureState(new
> tracked_objects::Tracked())) {
> On 2011/01/04 20:57:13, awong wrote:
>
>> On 2011/01/04 19:14:58, brettw wrote:
>> > Actually NewRunnableMethod of course make a "new" runnable method,
>>
> which I
>
>> think
>> > is equivalent to the new inside of bind? So it's 3 versus 1?
>>
>
>  Right...really, the tr1::function<> reference should be moved into the
>>
> closure
>
>> state, and ClosureState should just contain a Tracked object.  That
>>
> should move
>
>> this from 3 allocations down to 2.  Also, passing/copying a closure
>>
> object would
>
>> become just one scoped_refptr copy.
>>
>
>  I think 2 allocations is as low as can be gotten with any callback
>>
> system that
>
>> wraps another unless you start playing with placement-new.  To get
>>
> back to 1 one
>
>> allocation, we'd need to drop the tr1::bind dependency.  This might be
>>
> a good
>
>> enough motivation to avoid tr1::bind.
>>
>
> I don't think tr1::bind exposes the allocator as a template parameter,
> so I don't know of any way to use placement new to get around this
> limitation.
>
> Stepping back a second, I want to revisit the whole wrapping thing.  As
> I understand it, the reason to wrap it is to simplify the API to make it
> easier to understand by hiding the details.  I think, that's possible
> without any overhead, if eliminate ClosureState.  I've proposed removing
> tracked_objects::Tracked from ClosureState, which I believe eliminates
> any reason to have ClosureState.  Closure should basically be
> tr1::function, with a more chromium-styled API to make it blend more
> easily into our codebase.


Take a look at this CL too then:

  http://codereview.chromium.org/6094005/diff/3001/base/prebind.h

Specifically, at prebind.h.  The "Thunk" class is closer to what Closure
probably should be I think...

-Albert

Powered by Google App Engine
This is Rietveld 408576698