Merge lp:~ahayzen/music-app/fix-canload-false-queueloaderworker into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 824
Merged at revision: 827
Proposed branch: lp:~ahayzen/music-app/fix-canload-false-queueloaderworker
Merge into: lp:music-app/remix
Diff against target: 115 lines (+48/-0)
2 files modified
WorkerModelLoader.qml (+8/-0)
music-app.qml (+40/-0)
To merge this branch: bzr merge lp:~ahayzen/music-app/fix-canload-false-queueloaderworker
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+248078@code.launchpad.net

Commit message

* Wait until all worker threads have stopped after calling canLoad=false

Description of the change

* Wait until all worker threads have stopped after calling canLoad=false

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

I've managed to break the timing/race condition part of the fix.

Before a large queue is loaded I play an album containing "Song 2" by the Blur: http://i.imgur.com/9UvRrrw.png. However, when I switch to the queue I see that the queue contains the original large list: http://i.imgur.com/FFBJXR6.png. When I restart the app I get the correct queue (Song 2).

The above might have been a really tight race condition though. I haven't been able to reproduce it more than just once.

review: Needs Information
822. By Andrew Hayzen

* Wait until all worker threads have stopped after calling canLoad=false

823. By Andrew Hayzen

* Revert dropping of sync as we now wait for workers

824. By Andrew Hayzen

* Fix for indenting

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

LGTM! Race condition doesn't appear any longer and this still allows the queue to function. External stimuli such as content-hub and the uri-handlers still function as intended.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'WorkerModelLoader.qml'
2--- WorkerModelLoader.qml 2014-10-29 02:44:47 +0000
3+++ WorkerModelLoader.qml 2015-02-01 03:35:19 +0000
4@@ -29,6 +29,7 @@
5 property var list
6 property var model
7 property bool preLoadComplete: false
8+ property int processing: 0
9 property int syncFactor: 5
10
11 onCanLoadChanged: {
12@@ -54,6 +55,8 @@
13 completed = true
14 }
15
16+ processing--;
17+
18 return; // do not continue from a sync 'pong' only from a process/clear
19 }
20
21@@ -72,10 +75,13 @@
22 if (i === 1) { // sync after the first item to prevent empty states
23 sync()
24 }
25+
26+ processing--; // minus at end to cause count to go 1->2->1 not 1->0->1
27 }
28
29 function clear() {
30 if (list !== undefined) {
31+ processing++
32 sendMessage({'clear': true, 'model': model})
33 }
34 }
35@@ -85,6 +91,7 @@
36 {
37 if (i < list.length) {
38 console.log(JSON.stringify(list[i]));
39+ processing++;
40 sendMessage({'add': list[i], 'model': model});
41 i++;
42 } else {
43@@ -100,6 +107,7 @@
44
45 function sync()
46 {
47+ processing++;
48 sendMessage({'sync': true, 'model': model});
49 }
50 }
51
52=== modified file 'music-app.qml'
53--- music-app.qml 2015-01-29 02:42:38 +0000
54+++ music-app.qml 2015-02-01 03:35:19 +0000
55@@ -202,6 +202,11 @@
56 // Stop queue loading in the background
57 queueLoaderWorker.canLoad = false
58
59+ if (queueLoaderWorker.processing > 0) {
60+ waitForWorker.workerStop(queueLoaderWorker, processFile, [uri, play])
61+ return;
62+ }
63+
64 uri = decodeURIComponent(uri);
65
66 // Lookup track in songs model
67@@ -541,6 +546,33 @@
68 }
69 }
70
71+ // A timer to wait for a worker to stop
72+ Timer {
73+ id: waitForWorker
74+ interval: 16
75+ repeat: true
76+
77+ property var func
78+ property var params // don't use args/arguments as they are already defined/internal
79+ property WorkerScript worker
80+
81+ onTriggered: {
82+ if (worker.processing === 0) {
83+ stop()
84+ func.apply(this, params)
85+ }
86+ }
87+
88+ // Waits until the worker has stopped and then calls the func(*params)
89+ function workerStop(worker, func, params)
90+ {
91+ waitForWorker.func = func
92+ waitForWorker.params = params
93+ waitForWorker.worker = worker
94+ start()
95+ }
96+ }
97+
98 // Run on startup
99 Component.onCompleted: {
100 customdebug("Version "+appVersion) // print the curren version
101@@ -654,6 +686,14 @@
102 }
103
104 function trackClicked(model, index, play, clear) {
105+ // Stop queue loading in the background
106+ queueLoaderWorker.canLoad = false
107+
108+ if (queueLoaderWorker.processing > 0) {
109+ waitForWorker.workerStop(queueLoaderWorker, trackClicked, [model, index, play, clear])
110+ return;
111+ }
112+
113 // TODO: remove once playlists uses U1DB
114 if (model.hasOwnProperty("linkLibraryListModel")) {
115 model = model.linkLibraryListModel;

Subscribers

People subscribed via source and target branches