Merge lp:~mhr3/unity-lens-files/cancel-timer into lp:~unity-team/unity-lens-files/libunity7-compatible

Proposed by Michal Hruby on 2013-04-29
Status: Merged
Approved by: Paweł Stołowski on 2013-04-30
Approved revision: 257
Merged at revision: 258
Proposed branch: lp:~mhr3/unity-lens-files/cancel-timer
Merge into: lp:~unity-team/unity-lens-files/libunity7-compatible
Diff against target: 40 lines (+16/-1)
2 files modified
src/Makefile.am (+2/-0)
src/daemon.vala (+14/-1)
To merge this branch: bzr merge lp:~mhr3/unity-lens-files/cancel-timer
Reviewer Review Type Date Requested Status
Paweł Stołowski 2013-04-29 Approve on 2013-04-30
PS Jenkins bot (community) continuous-integration Approve on 2013-04-29
Review via email: mp+161463@code.launchpad.net

Commit message

Add support to cancel timer to save a few milliseconds

Description of the change

Add support to cancel timer to save a few milliseconds.

Currently new search can't run until the old one finishes, and since we used a non-cancellable timer in the files lens, we were adding up to ~500ms of latency.

To post a comment you must log in.
Paweł Stołowski (stolowski) wrote :

Works fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2013-03-12 13:43:11 +0000
3+++ src/Makefile.am 2013-04-29 17:54:25 +0000
4@@ -8,6 +8,8 @@
5 pkglibexec_PROGRAMS = \
6 unity-files-daemon
7
8+AM_CFLAGS = -w
9+
10 unity_files_daemon_CPPFLAGS = \
11 -DDATADIR=\"$(DATADIR)\" \
12 -DPKGDATADIR=\"$(PKGDATADIR)\" \
13
14=== modified file 'src/daemon.vala'
15--- src/daemon.vala 2013-03-12 13:43:11 +0000
16+++ src/daemon.vala 2013-04-29 17:54:25 +0000
17@@ -839,9 +839,22 @@
18 int dirs_category = Categories.FOLDERS)
19 throws Error
20 {
21+ cancellable.set_error_if_cancelled (); // throws IOError
22 /* Wait a while before starting the locate search */
23- Timeout.add_full (Priority.LOW, timeout, perform_locate.callback);
24+ uint timer_src_id = Timeout.add_full (Priority.LOW, timeout,
25+ perform_locate.callback);
26+ var canc_id = cancellable.connect (() =>
27+ {
28+ if (timer_src_id != 0) Source.remove (timer_src_id);
29+ timer_src_id = 0;
30+ // can't invoke directly, the disconnect call would deadlock
31+ Idle.add_full (Priority.DEFAULT, perform_locate.callback);
32+ });
33 yield;
34+
35+ cancellable.disconnect (canc_id);
36+ if (timer_src_id != 0) Source.remove (timer_src_id);
37+
38 cancellable.set_error_if_cancelled (); // throws IOError
39
40 var results = yield Locate.locate (query, cancellable);

Subscribers

People subscribed via source and target branches

to all changes: