From e232eeac42f483727afd2a82de6968907489ad9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 3 Nov 2015 12:42:31 -0500 Subject: [PATCH 1/4] lib/core: intro `Task` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/core/kernel.nit | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index 650360ad7a..84bd84445e 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -1067,3 +1067,14 @@ extern class Pointer # Free the memory pointed by this pointer fun free `{ free(self); `} end + +# Task with a `main` method to be implemented by subclasses +# +# This class is provided for compatibility between different parallelization systems. +# It can be used to run a fragment of code on a different thread and +# to register a reaction to UI events. +interface Task + + # Main method of this task + fun main do end +end From 60f0d9fdf2478688b518340d2598a48b3ef39eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 3 Nov 2015 12:34:34 -0500 Subject: [PATCH 2/4] lib/android: intro `NativeActivity::run_on_ui_thread` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/activities.nit | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/android/activities.nit b/lib/android/activities.nit index ed8e1f6970..a4578994e6 100644 --- a/lib/android/activities.nit +++ b/lib/android/activities.nit @@ -40,4 +40,16 @@ extern class NativeActivity in "Java" `{ android.app.Activity `} # Notify the OS that this activity is done and should be closed fun finish in "Java" `{ self.finish(); `} + + # Execute `task.main` on the UI thread when possible + fun run_on_ui_thread(task: Task) import Task.main in "Java" `{ + final int final_task = task; + Runnable runnable = new Runnable() { + @Override + public void run() { + Task_main(final_task); + } + }; + self.runOnUiThread(runnable); + `} end From 971eac076c3bcb314bc21d42b0d4de088f0a488f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 3 Nov 2015 15:09:30 -0500 Subject: [PATCH 3/4] tests: update tests relying on the content of core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- tests/sav/error_class_glob.res | 1 + tests/sav/nituml_args3.res | 5 +++++ tests/sav/nituml_args4.res | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/tests/sav/error_class_glob.res b/tests/sav/error_class_glob.res index 3d8ae369d1..08a096b5dd 100644 --- a/tests/sav/error_class_glob.res +++ b/tests/sav/error_class_glob.res @@ -10,3 +10,4 @@ ../lib/core/kernel.nit:704,1--890,3: Error: `kernel#Int` does not specialize `module_0#Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:892,1--1060,3: Error: `kernel#Char` does not specialize `module_0#Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:1062,1--1069,3: Error: `kernel#Pointer` does not specialize `module_0#Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:1071,1--1080,3: Error: `kernel#Task` does not specialize `module_0#Object`. Possible duplication of the root class `Object`? diff --git a/tests/sav/nituml_args3.res b/tests/sav/nituml_args3.res index 700f951b29..ec356dacde 100644 --- a/tests/sav/nituml_args3.res +++ b/tests/sav/nituml_args3.res @@ -72,6 +72,11 @@ Pointer [ ] Object -> Pointer [dir=back arrowtail=open style=dashed]; +Task [ + label = "{interface\nTask||+ main()\l}" +] +Object -> Task [dir=back arrowtail=open style=dashed]; + A [ label = "{A|- _vpubA: nullable A\l- _vproA: nullable A\l- _vpriA: nullable A\l- _vpubA2: A\l- _vproA2: A\l- _vpriA2: A\l- _vpriB: nullable B\l- _vpriB2: B\l|+ pubA(a: A)\l# proA(a: A)\l- priA(a: A)\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l# vproA(): nullable A\l# vproA=(vproA: nullable A)\l- vpriA(): nullable A\l- vpriA=(vpriA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l# vproA2(): A\l# vproA2=(vproA2: A)\l- vpriA2(): A\l- vpriA2=(vpriA2: A)\l- priB(a: B)\l- vpriB(): nullable B\l- vpriB=(vpriB: nullable B)\l- vpriB2(): B\l- vpriB2=(vpriB2: B)\l}" ] diff --git a/tests/sav/nituml_args4.res b/tests/sav/nituml_args4.res index f01534c81e..a87d928250 100644 --- a/tests/sav/nituml_args4.res +++ b/tests/sav/nituml_args4.res @@ -72,6 +72,11 @@ Pointer [ ] Object -> Pointer [dir=back arrowtail=open style=dashed]; +Task [ + label = "{interface\nTask||+ main()\l}" +] +Object -> Task [dir=back arrowtail=open style=dashed]; + A [ label = "{A||+ pubA(a: A)\l+ vpubA(): nullable A\l+ vpubA=(vpubA: nullable A)\l+ vpubA2(): A\l+ vpubA2=(vpubA2: A)\l}" ] From 6bbbd860a81f70cb15cd110c363d8a313e7a26e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 3 Nov 2015 19:34:51 -0500 Subject: [PATCH 4/4] contrib/nitester: rename local class Task to TesterTask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/nitester/src/nitester.nit | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/nitester/src/nitester.nit b/contrib/nitester/src/nitester.nit index 8f2841589b..090405394a 100644 --- a/contrib/nitester/src/nitester.nit +++ b/contrib/nitester/src/nitester.nit @@ -170,7 +170,7 @@ abstract class Processor end # All tasks to be performed - var tasks = new Array[Task] + var tasks = new Array[TesterTask] # Gather and register all tasks fun create_tasks @@ -193,7 +193,7 @@ abstract class Processor continue label end - tasks.add new Task(engine, prog) + tasks.add new TesterTask(engine, prog) end label end end @@ -429,7 +429,7 @@ class Worker # Single C `int` to hold the next task id received from the `Controller` var task_buffer = new CIntArray(1) - # Manage communication with the `Controller` and execute dispatched `Task`s + # Manage communication with the `Controller` and execute dispatched `TesterTask`s fun work_on_tasks do var status = new Status @@ -566,7 +566,7 @@ end # # Note that a task may involve more than one program to test considering the # alts and args for the `test_program`. -class Task +class TesterTask # Engine to test executing `test_program` var engine: String @@ -576,12 +576,12 @@ class Task redef fun to_s do return "{engine} {test_program}" end -# Result of a `Task` +# Result of a `TesterTask` # -# There may be more than one result per `Task`. +# There may be more than one result per `TesterTask`. class Result - # `Task` associated to `self` - var task: Task + # `TesterTask` associated to `self` + var task: TesterTask # Argument index of the execution resulting in `self` var arg: Int