apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r377055 - /apr/apr/branches/1.2.x/file_io/win32/flock.c
Date Sat, 11 Feb 2006 21:05:26 GMT
Author: wrowe
Date: Sat Feb 11 13:05:25 2006
New Revision: 377055

URL: http://svn.apache.org/viewcvs?rev=377055&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
Backport: 377054

Modified:
    apr/apr/branches/1.2.x/file_io/win32/flock.c

Modified: apr/apr/branches/1.2.x/file_io/win32/flock.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/1.2.x/file_io/win32/flock.c?rev=377055&r1=377054&r2=377055&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/file_io/win32/flock.c (original)
+++ apr/apr/branches/1.2.x/file_io/win32/flock.c Sat Feb 11 13:05:25 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;



Mime
View raw message