YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include"mysys_priv.h" #include"mysys_err.h" #include <errno.h> /* Wait timeout for short lock (2 seconds) */ #define NANOSECONDS_TO_WAIT_FOR_LOCK 2000000000ULL
if (locktype == F_UNLCK)
{ if (UnlockFileEx(hFile, 0, liLength.LowPart, liLength.HighPart, &ov))
DBUG_RETURN(0); /* Forcompatibilitywithfcntlimplementation,ignoreerror, ifregionwasnotlocked
*/ if (GetLastError() == ERROR_NOT_LOCKED)
{
SetLastError(0);
DBUG_RETURN(0);
} goto error;
} elseif (locktype == F_RDLCK) /* read lock is mapped to a shared lock. */
dwFlags= 0; else /* write lock is mapped to an exclusive lock. */
dwFlags= LOCKFILE_EXCLUSIVE_LOCK;
/* Dropoldlockfirsttoavoiddoublelocking. DuringanalyzeofBug#38133(MyisamlogtestfailsonWindows) Imetthesituationthattheprogrammyisamloglockedthefile exclusively,thenadditionallyshared,thendidoneunlock,and thenblockedonanattempttolockitexclusivelyagain. Unlockingbeforeeverylockfixedtheproblem. Notethatthisintroducesaracecondition.Whentheapplication wantstoconvertanexclusivelockintoasharedone,itwillnow firstunlockthefileandthenlockitshared.Awaitingexclusive lockcouldstepinhere.ForreasonsdescribedinBug#38133and Bug#41124(ServerhangsonWindowswith--external-lockingafter INSERT...SELECT)andinthereviewthreadat http://lists.mysql.com/commits/60721 it seems to be the better optionthannottounlockhere. Ifonedaysomeonenoticesawayhowtodofilelocktypechanges onWindowswithoutunlockingbeforetakingthenewlock,please changethiscodeaccordinglytofixtheracecondition.
*/ if (!UnlockFileEx(hFile, 0, liLength.LowPart, liLength.HighPart, &ov) &&
(GetLastError() != ERROR_NOT_LOCKED)) goto error;
if (timeout_sec == WIN_LOCK_INFINITE)
{ if (LockFileEx(hFile, dwFlags, 0, liLength.LowPart, liLength.HighPart, &ov))
DBUG_RETURN(0); goto error;
}
dwFlags|= LOCKFILE_FAIL_IMMEDIATELY;
timeout_millis= timeout_sec * 1000; /* Try lock in a loop, until the lock is acquired or timeout happens */ for(i= 0; ;i+= WIN_LOCK_SLEEP_MILLIS)
{ if (LockFileEx(hFile, dwFlags, 0, liLength.LowPart, liLength.HighPart, &ov))
DBUG_RETURN(0);
if (GetLastError() != ERROR_LOCK_VIOLATION) goto error;
if (i >= timeout_millis) break;
Sleep(WIN_LOCK_SLEEP_MILLIS);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.