comparison example/task_queue/main.cc @ 492:9522c376a9fe

memcpy for param
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 09 Oct 2009 11:18:42 +0900
parents
children 58240647b23b
comparison
equal deleted inserted replaced
491:7cd207691af1 492:9522c376a9fe
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
34 repeat(void *arg)
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);
42 t->set_post(repeat, arg);
43 t->add_param(q->i);
44 t->add_param((int)arg);
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 */
78 // hello->set_cpu(SPE_ANY);
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
92 hello->add_param(i);
93 hello->add_param((int)&queues);
94 hello->set_post(repeat, (void*) &queues);
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 }