Mercurial > hg > Game > Cerium
diff example/post_function/main.cc @ 109:028ffc9c0375 draft
Cerium cvs version
author | gongo@gendarme.local |
---|---|
date | Wed, 12 Nov 2008 17:39:33 +0900 |
parents | |
children | c29b7163d6d9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/post_function/main.cc Wed Nov 12 17:39:33 2008 +0900 @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); + +static int count = 1; + +char *help_str = "Usage: ./post [-cpu spe_num] [-count N]\n\ + -count Number of print \"Hello, World!!\""; + +void +func1(void *p) +{ + int i = (int)p; + + printf("post function : %d\n", i--); + + if (i > 0) { + HTaskPtr next = manager->create_task(HELLO_TASK); + next->add_param(i); + next->set_post(func1, (void*)i); + next->set_cpu(SPE_ANY); + next->spawn(); + } +} + + +int +init(int argc, char **argv) +{ + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-count") == 0) { + count = atoi(argv[++i]); + } + if (strcmp(argv[i], "--help") == 0) { + printf("%s\n", help_str); + return -1; + } + } + + return 0; +} + +void +run_init(void) +{ + HTaskPtr task; + + task = manager->create_task(HELLO_TASK); + task->add_param(count); + task->set_post(func1, (void*)count); + task->set_cpu(SPE_ANY); + task->spawn(); +} + +int +cerium_main(int argc, char *argv[]) +{ + if (init(argc, argv) < 0) { + return -1; + } + + task_init(); + run_init(); + + return 0; +}