diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
commit | 7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch) | |
tree | 4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/vala/5 target glib | |
parent | Initial commit. (diff) | |
download | meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.tar.xz meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/vala/5 target glib')
-rw-r--r-- | test cases/vala/5 target glib/GLib.Thread.vala | 43 | ||||
-rw-r--r-- | test cases/vala/5 target glib/meson.build | 10 | ||||
-rw-r--r-- | test cases/vala/5 target glib/retcode.c | 5 |
3 files changed, 58 insertions, 0 deletions
diff --git a/test cases/vala/5 target glib/GLib.Thread.vala b/test cases/vala/5 target glib/GLib.Thread.vala new file mode 100644 index 0000000..fc82919 --- /dev/null +++ b/test cases/vala/5 target glib/GLib.Thread.vala @@ -0,0 +1,43 @@ +extern void * get_ret_code (); + +public class MyThread : Object { + public int x_times { get; private set; } + + public MyThread (int times) { + this.x_times = times; + } + + public int run () { + for (int i = 0; i < this.x_times; i++) { + stdout.printf ("ping! %d/%d\n", i + 1, this.x_times); + Thread.usleep (10000); + } + + // return & exit have the same effect + Thread.exit (get_ret_code ()); + return 43; + } +} + +public static int main (string[] args) { + // Check whether threads are supported: + if (Thread.supported () == false) { + stderr.printf ("Threads are not supported!\n"); + return -1; + } + + try { + // Start a thread: + MyThread my_thread = new MyThread (10); + Thread<int> thread = new Thread<int>.try ("My fst. thread", my_thread.run); + + // Wait until thread finishes: + int result = thread.join (); + // Output: `Thread stopped! Return value: 42` + stdout.printf ("Thread stopped! Return value: %d\n", result); + } catch (Error e) { + stdout.printf ("Error: %s\n", e.message); + } + + return 0; +} diff --git a/test cases/vala/5 target glib/meson.build b/test cases/vala/5 target glib/meson.build new file mode 100644 index 0000000..f285d9f --- /dev/null +++ b/test cases/vala/5 target glib/meson.build @@ -0,0 +1,10 @@ +project('valatest', 'vala', 'c') + +if not meson.is_unity() + add_global_arguments('-Werror', language : 'c') +endif + +valadeps = [dependency('glib-2.0', version : '>=2.32'), dependency('gobject-2.0')] + +e = executable('valaprog', 'GLib.Thread.vala', 'retcode.c', dependencies : valadeps) +test('valatest', e) diff --git a/test cases/vala/5 target glib/retcode.c b/test cases/vala/5 target glib/retcode.c new file mode 100644 index 0000000..df44de5 --- /dev/null +++ b/test cases/vala/5 target glib/retcode.c @@ -0,0 +1,5 @@ +void * +get_ret_code (void) +{ + return (void *) (int) 42; +} |