Mercurial > hg > Game > Cerium
changeset 1985:d703157bb280 draft
add Read mode in fileread
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Apr 2014 00:24:16 +0900 |
parents | 7bea670cdba0 |
children | c05e575da760 |
files | example/fileread/Func.h example/fileread/main.cc example/fileread/task_init.cc |
diffstat | 3 files changed, 35 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/example/fileread/Func.h Thu Apr 17 23:43:09 2014 +0900 +++ b/example/fileread/Func.h Fri Apr 18 00:24:16 2014 +0900 @@ -4,6 +4,7 @@ Print_task, RUN_READ_BLOCKS, MMAP, + READ, }; enum {
--- a/example/fileread/main.cc Thu Apr 17 23:43:09 2014 +0900 +++ b/example/fileread/main.cc Fri Apr 18 00:24:16 2014 +0900 @@ -101,6 +101,10 @@ filename = argv[i+1]; } else if (strcmp(argv[i], "-br") == 0) { READ_TYPE = BLOCKED_READ; + } else if (strcmp(argv[i], "-r") == 0) { + READ_TYPE = MY_READ; + } else if (strcmp(argv[i], "-m") == 0) { + READ_TYPE = MY_MMAP; } } @@ -122,13 +126,9 @@ FileReadPtr fr = (FileReadPtr)in; /*マッピングだよ!*/ - int map = MAP_PRIVATE; - st_mmap_t st_mmap; - int fd = fr->fd; - st_mmap.size = fr->filesize; - fr->read_text = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); - if (st_mmap.file_mmap == (caddr_t)-1) { + read(fd, fr->read_text, fr->filesize); + if (fr->read_text == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n"); perror(NULL); @@ -139,6 +139,29 @@ } +SchedDefineTask1(READ,my_read); + +static int +my_read(SchedTask *s, void *in, void *out) +{ + + FileReadPtr fr = (FileReadPtr)in; + /*マッピングだよ!*/ + + int map = MAP_PRIVATE; + + int fd = fr->fd; + fr->read_text = (char*)mmap(NULL,fr->filesize,PROT_READ,map,fd,(off_t)0); + if (fr->read_text == (caddr_t)-1) { + fprintf(stderr,"Can't mmap file\n"); + + perror(NULL); + exit(0); + } + + return 0; +} + static void run_start(TaskManager *manager,char *filename) { @@ -176,6 +199,9 @@ if (READ_TYPE == MY_MMAP) { run = manager->create_task(MMAP , (memaddr)&fr->self, sizeof(memaddr),0,0); printf("+ in mmap mode +\n"); + }else if (READ_TYPE == MY_READ) { + run = manager->create_task(READ , (memaddr)&fr->self, sizeof(memaddr),0,0); + printf("+ in Read mode +\n"); }else { //my_mmap(filename, fd, fr); printf("+ in Blocked Read mode +\n");
--- a/example/fileread/task_init.cc Thu Apr 17 23:43:09 2014 +0900 +++ b/example/fileread/task_init.cc Fri Apr 18 00:24:16 2014 +0900 @@ -6,6 +6,7 @@ SchedExternTask(Print_task); SchedExternTask(RUN_READ_BLOCKS); SchedExternTask(MMAP); +SchedExternTask(READ); /** * この関数は ../spe/spe-main と違って @@ -20,4 +21,5 @@ SchedRegister(Print_task); SchedRegister(RUN_READ_BLOCKS); SchedRegister(MMAP); + SchedRegister(READ); }