The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Thread safety

These changes was commited to the Birdfont repository Wed, 23 Sep 2015 16:01:39 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 23 Sep 2015 16:01:39 +0000 (18:01 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 23 Sep 2015 16:08:05 +0000 (18:08 +0200)
commit 412d81893be56ee351dfbc159edb2d9ba838c674
tree 0e04b430dac2239f914cbd660c17fc00375050b3
parent ca0c4b422f3924042959dc409c7d7dd6f9a6a18d
Thread safety
Vala disconnects signals automatically but not in a thread safe way.
This happens when the Task object is destroyed in a background thread.

libbirdfont/DrawingTools.vala
libbirdfont/Menu.vala
libbirdfont/MenuTab.vala
libbirdfont/Renderer/FallbackFont.vala
libbirdfont/Task.vala
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -772,8 +772,7 @@ auto_trace = new Tool ("autotrace", t_("Autotrace background image")); auto_trace.select_action.connect ((self) => { - Task t = new Task (); - t.task.connect (auto_trace_background); + Task t = new Task (auto_trace_background); MainWindow.native_window.run_background_thread (t); });
--- a/libbirdfont/Menu.vala +++ b/libbirdfont/Menu.vala @@ -168,8 +168,7 @@ MenuItem merge_paths = add_menu_item (t_("Merge Paths"), "merge_paths", "Glyph"); merge_paths.action.connect (() => { - Task t = new Task (); - t.task.connect (merge_selected_paths); + Task t = new Task (merge_selected_paths); MainWindow.native_window.run_background_thread (t); show_menu = false;
--- a/libbirdfont/MenuTab.vala +++ b/libbirdfont/MenuTab.vala @@ -611,8 +611,7 @@ return; } - Task t = new Task (); - t.task.connect (simplify); + Task t = new Task (simplify); MainWindow.native_window.run_background_thread (t); }
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -55,8 +55,7 @@ IdleSource idle = new IdleSource (); idle.set_callback (() => { - Task t = new Task (); - t.task.connect (init_font_config); + Task t = new Task (init_font_config); MainWindow.native_window.run_non_blocking_background_thread (t); return false; });
--- a/libbirdfont/Task.vala +++ b/libbirdfont/Task.vala @@ -16,9 +16,11 @@ public class Task : GLib.Object { - public signal void task (); + public delegate void Runnable (); + Runnable task; - public Task () { + public Task (Runnable r) { + task = r; } public void run () {