You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2006/02/11 22:04:05 UTC
svn commit: r377054 - /apr/apr/trunk/file_io/win32/flock.c
Author: wrowe
Date: Sat Feb 11 13:04:03 2006
New Revision: 377054
URL: http://svn.apache.org/viewcvs?rev=377054&view=rev
Log:
Windows 9x file locks will *never* block. Emulate this behavior
in a very crufty loop.
Although better than nothing, this code easily creates a starved
child waiting for a high-utilization lock. Since Win9x is marginally
supported, create expected faults rather than unexpected failures.
PR: 28714
Author: inoue <inoue ariel-networks.com>, wrowe
Modified:
apr/apr/trunk/file_io/win32/flock.c
Modified: apr/apr/trunk/file_io/win32/flock.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/flock.c?rev=377054&r1=377053&r2=377054&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/flock.c (original)
+++ apr/apr/trunk/file_io/win32/flock.c Sat Feb 11 13:04:03 2006
@@ -36,8 +36,26 @@
return apr_get_os_error();
}
else {
- if (!LockFile(thefile->filehand, 0, 0, len, 0))
- return apr_get_os_error();
+ /* On Win9x, LockFile() never blocks. Hack in a crufty poll.
+ *
+ * Note that this hack exposes threads to being unserviced forever,
+ * in the situation that the given lock has low availability.
+ * When implemented in the kernel, LockFile will typically use
+ * FIFO or round robin distribution to ensure all threads get
+ * one crack at the lock; but in this case we can't emulate that.
+ *
+ * However Win9x are barely maintainable anyways, if the user does
+ * choose to build to them, this is the best we can do.
+ */
+ while (!LockFile(thefile->filehand, 0, 0, len, 0)) {
+ DWORD err = GetLastError();
+ if ((err == ERROR_LOCK_VIOLATION) && !(type & APR_FLOCK_NONBLOCK))
+ {
+ Sleep(500); /* pause for a half second */
+ continue; /* ... and then poll again */
+ }
+ return APR_FROM_OS_ERROR(err);
+ }
}
return APR_SUCCESS;