annotate example/task_queue/ppe/Hello.cc @ 961:efee36d2f84c draft

fix QueueInfo
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 04 Aug 2010 23:05:59 +0900
parents 94d82f2c842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "SchedTask.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "Hello.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "Func.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "main.h"
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 /* これは必須 */
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 SchedDefineTask(Hello);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 static int
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 run(SchedTask *smanager, void *rbuf, void *wbuf)
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 {
625
94d82f2c842f 64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 493
diff changeset
15 long task_id = (long)smanager->get_param(0);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 QueuePtr q = (QueuePtr) smanager->get_param(1);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 smanager->printf("[%d] Hello, World!!\n", task_id);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 for(int i=0;i<100;i++) {
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
21 QueueInfo<TaskQueue> *i0 = q->q[i%MAX_QUEUE];
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
22 QueueInfo<TaskQueue> *i1 = q->q[(i+1)%MAX_QUEUE];
493
2a7a9f80b8e7 fix free conflict.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 492
diff changeset
23 TaskQueue *q0;
2a7a9f80b8e7 fix free conflict.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 492
diff changeset
24 TaskQueue *q1;
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 switch(q->m->get_random() % 4) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 case 0:
961
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
28 q0 = i0->create(); i0->init(0);
efee36d2f84c fix QueueInfo
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 625
diff changeset
29 q1 = i1->create(); i1->init(0);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 i1->addLast(q0);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 i0->addLast(q1);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 break;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 case 1:
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 if (TaskQueue *p = i0->poll()) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 i1->addLast(p);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 break;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 case 2:
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 if (TaskQueue *p = i1->poll()) {
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 i0->addLast(p);
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 break;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 case 3:
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 if (TaskQueue *p = i0->poll()) {
493
2a7a9f80b8e7 fix free conflict.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 492
diff changeset
45 i0->free_(p);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if (TaskQueue *p = i1->poll()) {
493
2a7a9f80b8e7 fix free conflict.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 492
diff changeset
48 i1->free_(p);
492
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 break;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 return 0;
6b2dda81ea9d memcpy for param
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }