Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Issue 29367003: Issue #4711 - Rewrite legacy thread facilities

Created:
Dec. 7, 2016, 4:44 p.m. by Eric
Modified:
May 12, 2017, 2:45 p.m.
Reviewers:
sergei, Felix Dahlke, hub
Visibility:
Public.

Description

Issue #4711 - Rewrite legacy thread facilities Remove classes `Thread`, `Mutex`, and `Lock` and all tests for them. Remove all associated files. Replace `AdblockPlus::Sleep()` with `std::this_thread::sleep_for()`. Separate concerns by unlinking task specification, memory allocation, and scheduling. Add class `Scheduler`, which runs tasks with the same policy as before, namely, run immediately in a single-use thread. This scheduler is intended to be tranistory. Replace derivation from class `Thread` with writing tasks as function objects. In practice all this means is renaming old `Run` functions to `operator()`. Rename all names "...Thread" to "...Task". Improve memory handling for tasks by using `shared_ptr` instead of raw `new` and `delete`. Introduce adapter class `HeapFunction` to replicate the existing pattern of memory allocation. Add utility function `MakeHeapFunction`.

Patch Set 1 #

Total comments: 13
Unified diffs Side-by-side diffs Delta from patch set Stats (+209 lines, -379 lines) Patch
M libadblockplus.gyp View 2 chunks +1 line, -2 lines 0 comments Download
M src/FileSystemJsObject.cpp View 10 chunks +41 lines, -38 lines 0 comments Download
M src/FilterEngine.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
M src/GlobalJsObject.cpp View 4 chunks +12 lines, -14 lines 1 comment Download
A src/Scheduler.h View 1 chunk +78 lines, -0 lines 6 comments Download
A src/Scheduler.cpp View 1 chunk +38 lines, -0 lines 3 comments Download
R src/Thread.h View 1 chunk +0 lines, -76 lines 3 comments Download
R src/Thread.cpp View 1 chunk +0 lines, -113 lines 0 comments Download
M src/WebRequestJsObject.cpp View 4 chunks +8 lines, -8 lines 0 comments Download
M test/BaseJsTest.h View 2 chunks +3 lines, -2 lines 0 comments Download
M test/FileSystemJsObject.cpp View 8 chunks +9 lines, -10 lines 0 comments Download
M test/FilterEngine.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
M test/GlobalJsObject.cpp View 4 chunks +3 lines, -4 lines 0 comments Download
M test/Prefs.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
R test/Thread.cpp View 1 chunk +0 lines, -95 lines 0 comments Download
M test/UpdateCheck.cpp View 6 chunks +6 lines, -6 lines 0 comments Download
M test/WebRequest.cpp View 5 chunks +4 lines, -5 lines 0 comments Download

Messages

Total messages: 19
Eric
This change cleans up code structure while eliminating the old `Thread` code. Overall, these changes ...
Dec. 7, 2016, 6:06 p.m. (2016-12-07 18:06:25 UTC) #1
sergei
https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.cpp File src/Scheduler.cpp (right): https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.cpp#newcode36 src/Scheduler.cpp:36: auto th = std::thread(SingleUseThreadMain, task); SingleUseThreadMain is definitely redundant ...
Jan. 16, 2017, 2:50 p.m. (2017-01-16 14:50:13 UTC) #2
Eric
All the suggestions here are about definitions that are eliminated in later changes. https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.cpp File ...
Jan. 16, 2017, 3:20 p.m. (2017-01-16 15:20:16 UTC) #3
sergei
On 2017/01/16 15:20:16, Eric wrote: > All the suggestions here are about definitions that are ...
Jan. 17, 2017, 8:41 a.m. (2017-01-17 08:41:02 UTC) #4
Eric
On 2017/01/17 08:41:02, sergei wrote: > However, later changes will be later. No, the later ...
Jan. 17, 2017, 1:37 p.m. (2017-01-17 13:37:13 UTC) #5
sergei
I hope I have not missed anything in the rest reviews. There is no usage ...
Jan. 17, 2017, 1:40 p.m. (2017-01-17 13:40:54 UTC) #6
Eric
On 2017/01/17 13:40:54, sergei wrote: > I think that not > introducing HeapFunction will simplify ...
Jan. 17, 2017, 1:58 p.m. (2017-01-17 13:58:09 UTC) #7
sergei
On 2017/01/17 13:58:09, Eric wrote: ... > I'm going to repeat the following, because I ...
Jan. 17, 2017, 2:04 p.m. (2017-01-17 14:04:31 UTC) #8
Eric
On 2017/01/17 14:04:31, sergei wrote: > LGTM if it goes into branch (pay attention we ...
Jan. 17, 2017, 3:25 p.m. (2017-01-17 15:25:49 UTC) #9
sergei
On 2017/01/17 15:25:49, Eric wrote: > On 2017/01/17 14:04:31, sergei wrote: > > LGTM if ...
Jan. 17, 2017, 3:30 p.m. (2017-01-17 15:30:10 UTC) #10
Eric
> On 2017/01/17 15:25:49, Eric wrote: > > Branch created. Bookmark "master" left where it ...
Jan. 17, 2017, 3:38 p.m. (2017-01-17 15:38:52 UTC) #11
Eric
P.S. I think it will go much faster if I do push all the reviews. ...
Jan. 17, 2017, 3:41 p.m. (2017-01-17 15:41:25 UTC) #12
sergei
On 2017/01/17 15:38:52, Eric wrote: > > On 2017/01/17 15:25:49, Eric wrote: > > > ...
Jan. 17, 2017, 3:59 p.m. (2017-01-17 15:59:33 UTC) #13
Eric
On 2017/01/17 15:59:33, sergei wrote: > Mercurial branches are not mapped to git, > https://github.com/adblockplus/libadblockplus/branches. ...
Jan. 17, 2017, 4:10 p.m. (2017-01-17 16:10:14 UTC) #14
Eric
Still awaiting response about whether to commit the branch this change set begins on (1) ...
Jan. 19, 2017, 3:33 p.m. (2017-01-19 15:33:32 UTC) #15
Felix Dahlke
On 2017/01/19 15:33:32, Eric wrote: > Still awaiting response about whether to commit the branch ...
Jan. 19, 2017, 3:36 p.m. (2017-01-19 15:36:00 UTC) #16
Eric
On 2017/01/19 15:36:00, Felix Dahlke wrote: > Haven't read up on the entire discussion Ah, ...
Jan. 19, 2017, 4:06 p.m. (2017-01-19 16:06:41 UTC) #17
Felix Dahlke
On 2017/01/19 16:06:41, Eric wrote: > On 2017/01/19 15:36:00, Felix Dahlke wrote: > > Haven't ...
Jan. 19, 2017, 4:30 p.m. (2017-01-19 16:30:50 UTC) #18
hub
May 12, 2017, 2:45 p.m. (2017-05-12 14:45:40 UTC) #19
Eric,

We would really like to move forward and merge this (and other changes) in the
master branch.

Master has evolved a bit in since the original submission and this patch will
need a probably non trivial rebasing. Recent changes in master include getting
rid of JsValuePtr and other Ptr, changes in the tests, etc.

First an foremost, you need to move out the changes for replacing
AdblockPlus::Sleep() with std::this_thread::sleep_for() into a different patch.
This is really a standalone change and we'll review it quickly to get it in
first.

For the main part, on the review request, a few things need to be addressed. As
it was already outlined, removing bits that are not needed at the present time
would help make the changeset smaller. The smaller, the easier it will be to
move forward with this and the other changes you have been waiting for.

See my inline comments. 

Let me know if you have questions or need any help. Thanks!

https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.cpp
File src/Scheduler.cpp (right):

https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.cpp#n...
src/Scheduler.cpp:36: auto th = std::thread(SingleUseThreadMain, task);
With the other suggestion with task that is a unique_ptr<T>, you could just do 

// can't capture a unique_ptr<> in a lambda
std::shared_ptr<T> pt(std::move(task));
auto th = std::thread([pt]() { (*pt)(); });

https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.h
File src/Scheduler.h (right):

https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.h#new...
src/Scheduler.h:58: HeapFunction<T> MakeHeapFunction(std::shared_ptr<T> body)
If this is needed for something we want to remove, why the change? You can still
enforce the "single use" semantics with the move semantics and unique_ptr<>.
(based on how it is used in this changeset)

https://codereview.adblockplus.org/29367003/diff/29367004/src/Scheduler.h#new...
src/Scheduler.h:75: static void
StartImmediatelyInSingleUseThread(std::function<void()> task);
Here we could just take a std::unique_ptr<T>&& as a parameter, and what's above
is no longer needed. (T is a template parameter, since there is no more base
class of the "task")

Powered by Google App Engine
This is Rietveld