annotate example/Null/main.cc @ 1285:e38a4f3e238d draft

add NullTask
author Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 Nov 2011 16:20:46 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1285
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <stdlib.h>
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <string.h>
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "TaskManager.h"
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "Func.h"
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 extern void task_init(void);
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 extern TaskManager *manager;
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 static long task_num = 10;
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 /* help文章 */
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 const char *usr_help_str = "Usage: ./null [-cpu spe_num] [-num N]\n\
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 -cpu Number of SPE (default 1) \n\
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 -num Task Num (default 10)";
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 int
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 init(int argc, char **argv)
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 for (int i = 1; argv[i]; ++i) {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 if (strcmp(argv[i], "-num") == 0) {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 task_num = atoi(argv[++i]);
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 return 0;
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 void
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 null_init(TaskManager *manager)
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 // Create Task
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 for (long i = 0; i < task_num; i++) {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 HTask *null = manager->create_task(NullTask);
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 null->set_cpu(SPE_ANY);
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 null->spawn();
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 int
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 TMmain(TaskManager *manager, int argc, char *argv[])
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 if (init(argc, argv) < 0) {
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 return -1;
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 task_init();
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 null_init(manager);
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 return 0;
e38a4f3e238d add NullTask
Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 }