Mercurial > hg > Game > Cerium
changeset 1998:ed30952c240e draft
change function read() to pread() in my_read
author | masa |
---|---|
date | Tue, 22 Apr 2014 00:58:37 +0900 |
parents | 48419ad1ade5 |
children | 278e6ae50b72 |
files | example/word_count/main.cc |
diffstat | 1 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/example/word_count/main.cc Mon Apr 21 19:54:45 2014 +0900 +++ b/example/word_count/main.cc Tue Apr 22 00:58:37 2014 +0900 @@ -50,18 +50,23 @@ my_read(char *filename, WordCount *w, TaskManager *manager) { long fd = w->fd; + long r_filesize = w->read_filesize; if ((fd=open(filename,O_RDONLY,0666))==0) { fprintf(stderr,"can't open %s\n",filename); } - //madvise(w->file_mmap, w->read_filesize, POSIX_MADV_NORMAL); w->file_mmap = (char*)manager->allocate(w->read_filesize); - int read_check = read(fd, w->file_mmap, (long)w->read_filesize); - if (read_check == -1) { - fprintf(stderr,"Can't Read file\n"); - perror(NULL); - exit(0); + + long one_read_size = 1024 * 1024 * 1024; // 1GB + + for (int i = 0; 0 < r_filesize; i++) { + if (r_filesize > one_read_size) { + pread(fd, w->file_mmap + i*one_read_size, one_read_size,i*one_read_size); + }else if ((r_filesize < one_read_size) && (r_filesize != 0)) { + pread(fd, w->file_mmap + i*one_read_size, r_filesize,i*one_read_size); + } + r_filesize -= one_read_size; } if (w->file_mmap == (caddr_t)-1) { @@ -301,7 +306,7 @@ if (read_type == BLOCKED_READ) { - printf("[block read mode]\n"); + printf("[blocked read mode]\n"); w->file_mmap = (char*)manager->allocate(w->read_filesize); }else if (read_type == MY_READ) { printf("[single read mode]\n");