Mercurial > hg > Game > Cerium
changeset 1691:6b3991ac3f07 draft
changed mmap to fread.
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 17 Sep 2013 22:08:36 +0900 |
parents | aff937b6a26a |
children | 13ffed43fe68 |
files | example/regex_mas/main.cc |
diffstat | 1 files changed, 34 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/example/regex_mas/main.cc Thu Sep 12 17:13:52 2013 +0900 +++ b/example/regex_mas/main.cc Tue Sep 17 22:08:36 2013 +0900 @@ -88,6 +88,38 @@ } +static st_mmap_t +my_fread(TaskManager *manager,char *filename) +{ + + /*マッピングだよ!*/ + FILE *fd; + st_mmap_t st_mmap; + struct stat sb; + + if ((fd=fopen(filename,"r"))==NULL) { + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fileno(fd),&sb)) { + fprintf(stderr,"can't fstat %s\n",filename); + } + + /*sizeをページングサイズの倍数にあわせる*/ + st_mmap.size = fix_byte(sb.st_size,4096); + + st_mmap.file_mmap = (char*)manager->allocate(st_mmap.size); + fread(st_mmap.file_mmap,st_mmap.size,1,fd); + if (st_mmap.file_mmap == (caddr_t)-1) { + fprintf(stderr,"Can't mmap file\n"); + perror(NULL); + exit(0); + } + + return st_mmap; + +} + static void run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) { @@ -253,7 +285,8 @@ HTaskPtr t_print; st_mmap_t st_mmap; - st_mmap = my_mmap(filename); + //st_mmap = my_mmap(filename); + st_mmap = my_fread(manager,filename); WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); // bzero(w,sizeof(WordCount));