[simple-scan] Make cancellation of saving feels instantaneous
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [simple-scan] Make cancellation of saving feels instantaneous
- Date: Tue, 30 May 2017 07:58:36 +0000 (UTC)
commit c73eecfcd4d3f080eb957e38c79e3cd634e69508
Author: Stéphane Fillion <stphanef3724 gmail com>
Date: Mon May 29 09:09:38 2017 -0400
Make cancellation of saving feels instantaneous
src/app-window.vala | 3 +--
src/book.vala | 12 +++++-------
2 files changed, 6 insertions(+), 9 deletions(-)
---
diff --git a/src/app-window.vala b/src/app-window.vala
index dbe87af..792e0dc 100644
--- a/src/app-window.vala
+++ b/src/app-window.vala
@@ -1813,6 +1813,7 @@ private class CancellableProgressBar : Gtk.HBox
button.visible = true;
button.clicked.connect (() =>
{
+ set_visible (false);
cancellable.cancel ();
});
pack_start (button);
@@ -1834,6 +1835,4 @@ private class CancellableProgressBar : Gtk.HBox
return false;
});
}
-
-
}
diff --git a/src/book.vala b/src/book.vala
index eaffc41..be49dc0 100644
--- a/src/book.vala
+++ b/src/book.vala
@@ -173,6 +173,7 @@ private class BookSaver
private Mutex progression_mutex;
private Cancellable? cancellable;
private AsyncQueue<WriteTask> write_queue;
+ private ThreadPool<EncodeTask> encoder;
private SourceFunc save_async_callback;
/* save_async get called in the main thread to start saving. It
@@ -220,7 +221,7 @@ private class BookSaver
encode_delegate = encode_pdf;
break;
}
- var encoder = new ThreadPool<EncodeTask>.with_owned_data (encode_delegate, (int) get_num_processors
(), false);
+ encoder = new ThreadPool<EncodeTask>.with_owned_data (encode_delegate, (int) get_num_processors (),
false);
/* Configure a writer */
ThreadFunc<Error?>? write_delegate = null;
@@ -251,9 +252,6 @@ private class BookSaver
/* Waiting for saving to finish */
yield;
- /* At this point, any remaining encode_task ought to remain unprocessed */
- ThreadPool.free ((owned) encoder, true, true);
-
/* Any error from any thread ends up here */
var error = writer.join ();
if (error != null)
@@ -269,9 +267,6 @@ private class BookSaver
private void encode_png (owned EncodeTask encode_task)
{
- if (cancellable.is_cancelled ())
- return;
-
var page = encode_task.page;
var icc_data = page.get_icc_data_encoded ();
var write_task = new WriteTask ();
@@ -830,6 +825,9 @@ private class BookSaver
* cancelled */
private void finished_saving ()
{
+ /* At this point, any remaining encode_task ought to remain unprocessed */
+ ThreadPool.free ((owned) encoder, true, true);
+
/* Wake-up save_async method in main thread */
Idle.add ((owned)save_async_callback);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]