annotate example/fileread/ppe/Read.cc @ 1808:c25aa7edd1ba draft

fix conditional branch in fileread
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Wed, 11 Dec 2013 17:42:09 +0900
parents e08f6133f5d7
children ff4e06001518
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1721
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <string.h>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <unistd.h>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <sys/stat.h>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <iostream>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include <vector>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <cstdlib>
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "SchedTask.h"
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #include "Print.h"
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "Func.h"
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 /* これは必須 */
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 SchedDefineTask(Read);
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 static int
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 run(SchedTask *s, void *rbuf, void *wbuf)
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1721
diff changeset
18 {
1721
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 int *fd = (int *)s->get_input(rbuf,0); ///ファイルディスクリプタの受取
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
1808
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
21 long task_number = (long)s->get_param(0); //何番目のtaskか
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
22 long division_size = (long)s->get_param(1);
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
23 long read_size = (long)s->get_param(2);
1740
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1721
diff changeset
24
1808
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
25 char text[(long)read_size];
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
26
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
27 lseek(*fd, division_size* task_number,SEEK_SET); //lseekでどこから読み込むのか指定
c25aa7edd1ba fix conditional branch in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1802
diff changeset
28 read(*fd,text,(long)read_size);
1721
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
1802
e08f6133f5d7 change iterator to spawn in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1740
diff changeset
30 s->printf("[start task No. %d]\n",task_number);
e08f6133f5d7 change iterator to spawn in fileread
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents: 1740
diff changeset
31 s->printf("%s\n",text);
1721
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 return 0;
797e3ec1ca74 add fileread only example
Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }