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
=== modified file 'WorkerModelLoader.qml'
--- WorkerModelLoader.qml 2014-10-29 02:44:47 +0000
+++ WorkerModelLoader.qml 2015-02-01 03:35:19 +0000
@@ -29,6 +29,7 @@
29 property var list29 property var list
30 property var model30 property var model
31 property bool preLoadComplete: false31 property bool preLoadComplete: false
32 property int processing: 0
32 property int syncFactor: 533 property int syncFactor: 5
3334
34 onCanLoadChanged: {35 onCanLoadChanged: {
@@ -54,6 +55,8 @@
54 completed = true55 completed = true
55 }56 }
5657
58 processing--;
59
57 return; // do not continue from a sync 'pong' only from a process/clear60 return; // do not continue from a sync 'pong' only from a process/clear
58 }61 }
5962
@@ -72,10 +75,13 @@
72 if (i === 1) { // sync after the first item to prevent empty states75 if (i === 1) { // sync after the first item to prevent empty states
73 sync()76 sync()
74 }77 }
78
79 processing--; // minus at end to cause count to go 1->2->1 not 1->0->1
75 }80 }
7681
77 function clear() {82 function clear() {
78 if (list !== undefined) {83 if (list !== undefined) {
84 processing++
79 sendMessage({'clear': true, 'model': model})85 sendMessage({'clear': true, 'model': model})
80 }86 }
81 }87 }
@@ -85,6 +91,7 @@
85 {91 {
86 if (i < list.length) {92 if (i < list.length) {
87 console.log(JSON.stringify(list[i]));93 console.log(JSON.stringify(list[i]));
94 processing++;
88 sendMessage({'add': list[i], 'model': model});95 sendMessage({'add': list[i], 'model': model});
89 i++;96 i++;
90 } else {97 } else {
@@ -100,6 +107,7 @@
100107
101 function sync()108 function sync()
102 {109 {
110 processing++;
103 sendMessage({'sync': true, 'model': model});111 sendMessage({'sync': true, 'model': model});
104 }112 }
105}113}
106114
=== modified file 'music-app.qml'
--- music-app.qml 2015-01-29 02:42:38 +0000
+++ music-app.qml 2015-02-01 03:35:19 +0000
@@ -202,6 +202,11 @@
202 // Stop queue loading in the background202 // Stop queue loading in the background
203 queueLoaderWorker.canLoad = false203 queueLoaderWorker.canLoad = false
204204
205 if (queueLoaderWorker.processing > 0) {
206 waitForWorker.workerStop(queueLoaderWorker, processFile, [uri, play])
207 return;
208 }
209
205 uri = decodeURIComponent(uri);210 uri = decodeURIComponent(uri);
206211
207 // Lookup track in songs model212 // Lookup track in songs model
@@ -541,6 +546,33 @@
541 }546 }
542 }547 }
543548
549 // A timer to wait for a worker to stop
550 Timer {
551 id: waitForWorker
552 interval: 16
553 repeat: true
554
555 property var func
556 property var params // don't use args/arguments as they are already defined/internal
557 property WorkerScript worker
558
559 onTriggered: {
560 if (worker.processing === 0) {
561 stop()
562 func.apply(this, params)
563 }
564 }
565
566 // Waits until the worker has stopped and then calls the func(*params)
567 function workerStop(worker, func, params)
568 {
569 waitForWorker.func = func
570 waitForWorker.params = params
571 waitForWorker.worker = worker
572 start()
573 }
574 }
575
544 // Run on startup576 // Run on startup
545 Component.onCompleted: {577 Component.onCompleted: {
546 customdebug("Version "+appVersion) // print the curren version578 customdebug("Version "+appVersion) // print the curren version
@@ -654,6 +686,14 @@
654 }686 }
655687
656 function trackClicked(model, index, play, clear) {688 function trackClicked(model, index, play, clear) {
689 // Stop queue loading in the background
690 queueLoaderWorker.canLoad = false
691
692 if (queueLoaderWorker.processing > 0) {
693 waitForWorker.workerStop(queueLoaderWorker, trackClicked, [model, index, play, clear])
694 return;
695 }
696
657 // TODO: remove once playlists uses U1DB697 // TODO: remove once playlists uses U1DB
658 if (model.hasOwnProperty("linkLibraryListModel")) {698 if (model.hasOwnProperty("linkLibraryListModel")) {
659 model = model.linkLibraryListModel;699 model = model.linkLibraryListModel;

Subscribers

People subscribed via source and target branches