1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
DWORD WINAPI FileReadThreadEntry(LPVOID lpThreadParameter)
{
//File access with cache enabled
input * in = (input*) lpThreadParameter;
LPCTSTR path = (LPCTSTR) in->path;
HANDLE fp = CreateFile(
path,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,//|FILE_FLAG_NO_BUFFERING,
NULL);
unsigned int sPos = in->starting;
int * result = in->r;
if(fp != NULL)
{
unsigned long pos;
bool bRead;
DWORD bNum;
for (int i=0; i<length/(threadCount*interval);i++)
{
pos = i * interval;
if ((SetFilePointer(fp,(sPos+pos),NULL,FILE_BEGIN)!=0))
{
if ((bRead = ReadFile(fp,&result[sPos/interval + i],512,&bNum,NULL))== true)
{
InterlockedIncrement(&completeIOs);
}
else
{
printf("file read err...\n");
exit(-1);
}
}
}
CloseHandle(fp);
fp = NULL;
}
else
{
printf("File open err... \n");
exit(-1);
}
}
|