2017-05-15 13:55:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* machinarium.
|
|
|
|
*
|
|
|
|
* Cooperative multitasking engine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <machinarium.h>
|
|
|
|
#include <machinarium_test.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_condition_fiber(void *arg)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
int rc = machine_condition(1000);
|
2017-05-15 13:55:10 +00:00
|
|
|
test(rc == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_waiter(void *arg)
|
|
|
|
{
|
|
|
|
int64_t a;
|
2017-05-17 14:23:21 +00:00
|
|
|
a = machine_create_fiber(test_condition_fiber, NULL);
|
2017-05-15 13:55:10 +00:00
|
|
|
test(a != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_sleep(0);
|
2017-05-15 13:55:10 +00:00
|
|
|
|
|
|
|
int rc;
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_signal(a);
|
2017-05-15 13:55:10 +00:00
|
|
|
test(rc != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machine_sleep(0);
|
|
|
|
machine_stop();
|
2017-05-15 13:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
test_condition0(void)
|
|
|
|
{
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_init();
|
|
|
|
|
|
|
|
int id;
|
2017-05-17 14:35:55 +00:00
|
|
|
id = machine_create("test", test_waiter, NULL);
|
2017-05-17 14:23:21 +00:00
|
|
|
test(id != -1);
|
2017-05-15 13:55:10 +00:00
|
|
|
|
|
|
|
int rc;
|
2017-05-17 14:23:21 +00:00
|
|
|
rc = machine_join(id);
|
2017-05-15 13:55:10 +00:00
|
|
|
test(rc != -1);
|
|
|
|
|
2017-05-17 14:23:21 +00:00
|
|
|
machinarium_free();
|
2017-05-15 13:55:10 +00:00
|
|
|
}
|