00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #include "db_int.h"
00013
00014
00015
00016
00017
00018
00019
00020 int
00021 __os_fdlock(dbenv, fhp, offset, acquire, nowait)
00022 DB_ENV *dbenv;
00023 DB_FH *fhp;
00024 int acquire, nowait;
00025 off_t offset;
00026 {
00027 int ret;
00028 DWORD low, high;
00029 OVERLAPPED over;
00030
00031 DB_ASSERT(F_ISSET(fhp, DB_FH_OPENED) &&
00032 fhp->handle != INVALID_HANDLE_VALUE);
00033
00034
00035
00036
00037
00038 DB_ASSERT(offset < (u_int64_t)INT64_MAX);
00039 offset = UINT64_MAX - offset;
00040 low = (DWORD)offset;
00041 high = (DWORD)(offset >> 32);
00042
00043 if (acquire) {
00044 if (nowait)
00045 RETRY_CHK_EINTR_ONLY(
00046 !LockFile(fhp->handle, low, high, 1, 0), ret);
00047 else if (__os_is_winnt()) {
00048 memset(&over, 0, sizeof over);
00049 over.Offset = low;
00050 over.OffsetHigh = high;
00051 RETRY_CHK_EINTR_ONLY(
00052 !LockFileEx(fhp->handle, LOCKFILE_EXCLUSIVE_LOCK,
00053 0, 1, 0, &over),
00054 ret);
00055 } else {
00056
00057 for (;;) {
00058 RETRY_CHK_EINTR_ONLY(
00059 !LockFile(fhp->handle, low, high, 1, 0),
00060 ret);
00061 if (ret != EAGAIN)
00062 break;
00063 __os_sleep(dbenv, 1, 0);
00064 }
00065 }
00066 } else
00067 RETRY_CHK_EINTR_ONLY(
00068 !UnlockFile(fhp->handle, low, high, 1, 0), ret);
00069
00070 return (ret);
00071 }