libowfat/io/iob_prefetch.c

56 lines
1.0 KiB
C
Raw Normal View History

2004-01-07 15:58:44 +00:00
#include "iob_internal.h"
#ifdef __MINGW32__
/* not supported */
void iob_prefetch(io_batch* b,uint64 bytes) {
(void)b;
(void)bytes;
}
#else
2004-01-07 15:58:44 +00:00
#include <stdio.h>
2004-02-21 17:26:57 +00:00
#include <sys/types.h>
2004-01-07 15:58:44 +00:00
#include <sys/mman.h>
void iob_prefetch(io_batch* b,uint64 bytes) {
volatile char x=0;
2004-01-07 15:58:44 +00:00
iob_entry* e,* last;
if (b->bytesleft==0) return;
last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b));
e=(iob_entry*)array_start(&b->b);
if (!e) return;
for (; e<last; ++e) {
if (e->type==FROMFILE) {
#ifdef MADV_WILLNEED
char* c;
c=mmap(0,bytes,PROT_READ,MAP_SHARED,e->fd,(e->offset|4095)+1);
madvise(c,bytes,MADV_WILLNEED);
munmap(c,bytes);
#else
2004-01-07 15:58:44 +00:00
char* c,* d;
2004-01-10 00:05:18 +00:00
uint64 before=bytes;
2004-01-10 00:12:18 +00:00
if (e->n<bytes) bytes=e->n;
2004-01-07 15:58:44 +00:00
if (e->n>=1000000) {
2004-01-10 00:09:30 +00:00
long l=e->offset&4095;
d=c=mmap(0,bytes,PROT_READ,MAP_SHARED,e->fd,(e->offset|4095)+1);
bytes-=l;
2004-01-07 15:58:44 +00:00
if (c!=MAP_FAILED) {
2004-01-10 00:09:30 +00:00
while (bytes>4095) {
2004-01-10 00:06:56 +00:00
x=*d;
2004-01-07 15:58:44 +00:00
bytes-=4096;
d+=4096;
}
}
2004-01-10 00:05:18 +00:00
munmap(c,before);
2004-01-07 15:58:44 +00:00
}
#endif
2004-01-07 15:58:44 +00:00
return;
}
}
2004-01-10 00:06:56 +00:00
(void)x;
2004-01-07 15:58:44 +00:00
}
#endif