2017-05-15 13:48:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinarium.
|
|
|
|
*
|
|
|
|
* Cooperative multitasking engine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <machinarium_test.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_child_a(void *arg)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_sleep(100);
|
2017-05-15 13:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_child_b(void *arg)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_sleep(300);
|
2017-05-15 13:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_waiter(void *arg)
|
|
|
|
{
|
|
|
|
int64_t a, b;
|
2017-05-17 14:23:21 +00:00
|
|
|
b = machine_create_fiber(test_child_b, NULL);
|
2017-05-15 13:48:28 +00:00
|
|
|
test(b != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
a = machine_create_fiber(test_child_a, NULL);
|
2017-05-15 13:48:28 +00:00
|
|
|
test(a != -1);
|
|
|
|
|
|
|
|
int rc;
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_wait(a);
|
2017-05-15 13:48:28 +00:00
|
|
|
test(rc == 0);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_wait(b);
|
2017-05-15 13:48:28 +00:00
|
|
|
test(rc == 0);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_stop();
|
2017-05-15 13:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
test_wait(void)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_init();
|
|
|
|
|
|
|
|
int id;
|
|
|
|
id = machine_create(test_waiter, NULL);
|
|
|
|
test(id != -1);
|
2017-05-15 13:48:28 +00:00
|
|
|
|
|
|
|
int rc;
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_join(id);
|
2017-05-15 13:48:28 +00:00
|
|
|
test(rc != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_free();
|
2017-05-15 13:48:28 +00:00
|
|
|
}
|