Mercurial > hg > Game > Cerium
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 |
rev | line source |
---|---|
492 | 1 #include <stdio.h> |
2 #include "SchedTask.h" | |
3 #include "Hello.h" | |
4 #include "Func.h" | |
5 #include "main.h" | |
6 | |
7 /* これは必須 */ | |
8 SchedDefineTask(Hello); | |
9 | |
10 | |
11 | |
12 static int | |
13 run(SchedTask *smanager, void *rbuf, void *wbuf) | |
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 | 16 QueuePtr q = (QueuePtr) smanager->get_param(1); |
17 | |
18 smanager->printf("[%d] Hello, World!!\n", task_id); | |
19 | |
20 for(int i=0;i<100;i++) { | |
961 | 21 QueueInfo<TaskQueue> *i0 = q->q[i%MAX_QUEUE]; |
22 QueueInfo<TaskQueue> *i1 = q->q[(i+1)%MAX_QUEUE]; | |
493 | 23 TaskQueue *q0; |
24 TaskQueue *q1; | |
492 | 25 |
26 switch(q->m->get_random() % 4) { | |
27 case 0: | |
961 | 28 q0 = i0->create(); i0->init(0); |
29 q1 = i1->create(); i1->init(0); | |
492 | 30 i1->addLast(q0); |
31 i0->addLast(q1); | |
32 break; | |
33 case 1: | |
34 if (TaskQueue *p = i0->poll()) { | |
35 i1->addLast(p); | |
36 } | |
37 break; | |
38 case 2: | |
39 if (TaskQueue *p = i1->poll()) { | |
40 i0->addLast(p); | |
41 } | |
42 break; | |
43 case 3: | |
44 if (TaskQueue *p = i0->poll()) { | |
493 | 45 i0->free_(p); |
492 | 46 } |
47 if (TaskQueue *p = i1->poll()) { | |
493 | 48 i1->free_(p); |
492 | 49 } |
50 break; | |
51 } | |
52 } | |
53 | |
54 | |
55 return 0; | |
56 } |