Mercurial > hg > Game > Cerium
annotate example/task_queue/main.cc @ 625:94d82f2c842f draft
64bit mode worked on Mac OS X.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 16 Nov 2009 10:59:55 +0900 |
parents | 278db3ca751d |
children | 5d48fa762a24 |
rev | line source |
---|---|
492 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 #include "main.h" | |
7 | |
8 extern void task_init(void); | |
9 | |
10 static int count = 1; | |
11 | |
12 extern TaskManager *manager; | |
13 | |
14 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\ | |
15 -cpu Number of SPE (default 1) \n\ | |
16 -count Number of task is print \"Hello, World!!\""; | |
17 | |
18 int | |
19 init(int argc, char **argv) | |
20 { | |
21 for (int i = 1; argv[i]; ++i) { | |
22 if (strcmp(argv[i], "-count") == 0) { | |
23 count = atoi(argv[++i]); | |
24 } | |
25 | |
26 } | |
27 | |
28 return 0; | |
29 } | |
30 | |
31 Queues queues; | |
32 | |
33 static void | |
619 | 34 repeat(SchedTask *s, void *arg, void *dm) |
492 | 35 { |
36 static int count = 4; | |
37 QueuePtr q = (QueuePtr) arg; | |
38 TaskManager *manager = q->m; | |
39 | |
40 if (count-->0) { | |
41 HTask *t = manager->create_task(HELLO_TASK); | |
619 | 42 t->set_post(repeat, arg, 0); |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
43 t->set_param(0,(memaddr)q->i); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
44 t->set_param(1,(memaddr)arg); |
492 | 45 t->spawn(); |
46 | |
47 printf("[PPE] Create Task : Hello count=%d id=%d\n\n",count, q->i); | |
48 } else { | |
49 printf("[PPE] End Task : Hello id=%d\n\n", q->i); | |
50 } | |
51 } | |
52 | |
53 void | |
54 hello_init(TaskManager *manager) | |
55 { | |
56 | |
57 if (count >MAX_QUEUE) return; | |
58 | |
59 queues.m = manager; | |
60 queues.i = 0; | |
61 for (int i = 0; i < MAX_QUEUE; i++) { | |
62 TaskQueueInfo *q = new TaskQueueInfo() ; | |
63 queues.q[i] = q; | |
64 } | |
65 | |
66 for (int i = 0; i < count; i++) { | |
67 /** | |
68 * Create Task | |
69 * create_task(Task ID); | |
70 */ | |
71 HTask *hello = manager->create_task(HELLO_TASK); | |
72 | |
73 /** | |
74 * Select CPU | |
75 * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY | |
76 * if you do not call this, execute PPE. | |
77 */ | |
496
67fb962f58fa
PS3 double linked TaskQueue worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
492
diff
changeset
|
78 hello->set_cpu(SPE_ANY); |
492 | 79 |
80 /** | |
81 * Set 32bits parameter | |
82 * add_param(32bit parameter); | |
83 */ | |
84 QueuePtr q = (QueuePtr) manager->allocate(sizeof(Queues)); | |
85 | |
86 q->i = i; | |
87 q->m = manager; | |
88 for (int j = 0; j < MAX_QUEUE; j++) { | |
89 q->q[j] = queues.q[j]; | |
90 } | |
91 | |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
92 hello->set_param(0,(memaddr)i); |
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
619
diff
changeset
|
93 hello->set_param(1,(memaddr)&queues); |
619 | 94 hello->set_post(repeat, (void*) &queues, 0); |
492 | 95 |
96 hello->spawn(); | |
97 } | |
98 } | |
99 | |
100 int | |
101 TMmain(TaskManager *manager, int argc, char *argv[]) | |
102 { | |
103 if (init(argc, argv) < 0) { | |
104 return -1; | |
105 } | |
106 | |
107 // Task Register | |
108 // ppe/task_init.cc | |
109 task_init(); | |
110 | |
111 hello_init(manager); | |
112 | |
113 return 0; | |
114 } |