Subject: Re: Make the git codebase thread-safe

From: Karsten Blees <[email-masked]>
Date: Thu, 13 Feb 2014 23:51:48 +0100

Am 13.02.2014 19:38, schrieb Zachary Turner:

> The only reason ReOpenFile is necessary at 
> all is because some code somewhere is mixing read-styles against the same 
> fd.
> 

I don't understand...ReadFile with OVERLAPPED parameter doesn't modify the HANDLE's file position, so you should be able to mix read()/pread() however you like (as long as read() is only called from one thread).

I tried without ReOpenFile and it seems to work like a charm, or am I missing something?

----8<----
ssize_t mingw_pread(int fd, void *buf, size_t count, off64_t offset)
{
	DWORD bytes_read;
	OVERLAPPED overlapped;
	memset(&overlapped, 0, sizeof(overlapped));
	overlapped.Offset = (DWORD) offset;
	overlapped.OffsetHigh = (DWORD) (offset >> 32);

	if (!ReadFile((HANDLE) _get_osfhandle(fd), buf, count, &bytes_read,
	    &overlapped)) {
		errno = err_win_to_posix(GetLastError());
		return -1;
	}
	return (ssize_t) bytes_read;
}