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