annotate example/post_function/main.cc @ 256:2c775d229cc6 draft

fix examples
author tkaito@localhost.localdomain
date Wed, 03 Jun 2009 16:14:06 +0900
parents 028ffc9c0375
children c29b7163d6d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <stdio.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <stdlib.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <string.h>
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include "TaskManager.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include "Func.h"
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 extern void task_init(void);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 static int count = 1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 char *help_str = "Usage: ./post [-cpu spe_num] [-count N]\n\
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 -count Number of print \"Hello, World!!\"";
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 func1(void *p)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
16 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 int i = (int)p;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 printf("post function : %d\n", i--);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21 if (i > 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22 HTaskPtr next = manager->create_task(HELLO_TASK);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 next->add_param(i);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24 next->set_post(func1, (void*)i);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 next->set_cpu(SPE_ANY);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 next->spawn();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 init(int argc, char **argv)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 for (int i = 1; argv[i]; ++i) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 if (strcmp(argv[i], "-count") == 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 count = atoi(argv[++i]);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 if (strcmp(argv[i], "--help") == 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 printf("%s\n", help_str);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47 void
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 run_init(void)
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 HTaskPtr task;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52 task = manager->create_task(HELLO_TASK);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 task->add_param(count);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 task->set_post(func1, (void*)count);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 task->set_cpu(SPE_ANY);
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
56 task->spawn();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
58
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
59 int
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 cerium_main(int argc, char *argv[])
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 if (init(argc, argv) < 0) {
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 return -1;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 }
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 task_init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 run_init();
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 return 0;
028ffc9c0375 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 }