msvcrt: Use fd critical section in _locking.
This commit is contained in:
parent
9a4cfbc3ed
commit
ffdd16cc0d
|
@ -1252,16 +1252,20 @@ void CDECL MSVCRT__unlock_file(MSVCRT_FILE *file)
|
||||||
*/
|
*/
|
||||||
int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes)
|
int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes)
|
||||||
{
|
{
|
||||||
|
ioinfo *info = get_ioinfo(fd);
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
DWORD cur_locn;
|
DWORD cur_locn;
|
||||||
HANDLE hand = msvcrt_fdtoh(fd);
|
|
||||||
|
|
||||||
TRACE(":fd (%d) handle (%p)\n",fd,hand);
|
TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
|
||||||
if (hand == INVALID_HANDLE_VALUE)
|
if (info->handle == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
release_ioinfo(info);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (mode < 0 || mode > 4)
|
if (mode < 0 || mode > 4)
|
||||||
{
|
{
|
||||||
|
release_ioinfo(info);
|
||||||
*MSVCRT__errno() = MSVCRT_EINVAL;
|
*MSVCRT__errno() = MSVCRT_EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1274,8 +1278,9 @@ int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes)
|
||||||
(mode==MSVCRT__LK_NBRLCK)?"_LK_NBRLCK":
|
(mode==MSVCRT__LK_NBRLCK)?"_LK_NBRLCK":
|
||||||
"UNKNOWN");
|
"UNKNOWN");
|
||||||
|
|
||||||
if ((cur_locn = SetFilePointer(hand, 0L, NULL, SEEK_CUR)) == INVALID_SET_FILE_POINTER)
|
if ((cur_locn = SetFilePointer(info->handle, 0L, NULL, SEEK_CUR)) == INVALID_SET_FILE_POINTER)
|
||||||
{
|
{
|
||||||
|
release_ioinfo(info);
|
||||||
FIXME ("Seek failed\n");
|
FIXME ("Seek failed\n");
|
||||||
*MSVCRT__errno() = MSVCRT_EINVAL; /* FIXME */
|
*MSVCRT__errno() = MSVCRT_EINVAL; /* FIXME */
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1286,16 +1291,17 @@ int CDECL MSVCRT__locking(int fd, int mode, LONG nbytes)
|
||||||
ret = 1; /* just to satisfy gcc */
|
ret = 1; /* just to satisfy gcc */
|
||||||
while (nretry--)
|
while (nretry--)
|
||||||
{
|
{
|
||||||
ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
|
ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
|
||||||
if (ret) break;
|
if (ret) break;
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mode == MSVCRT__LK_UNLCK)
|
else if (mode == MSVCRT__LK_UNLCK)
|
||||||
ret = UnlockFile(hand, cur_locn, 0L, nbytes, 0L);
|
ret = UnlockFile(info->handle, cur_locn, 0L, nbytes, 0L);
|
||||||
else
|
else
|
||||||
ret = LockFile(hand, cur_locn, 0L, nbytes, 0L);
|
ret = LockFile(info->handle, cur_locn, 0L, nbytes, 0L);
|
||||||
/* FIXME - what about error settings? */
|
/* FIXME - what about error settings? */
|
||||||
|
release_ioinfo(info);
|
||||||
return ret ? 0 : -1;
|
return ret ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue