You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Mladen Turk <mt...@mappingsoft.com> on 2001/08/13 13:24:13 UTC
[PATCH] apr_file_lock/unclock on WIN9X
Hi all,
The apr_file_lock uses the LockFileEx API function to lock the file which is
unsupported on WIN9X platform, so as apr_file_unlock which uses
UnlockFileEx.
The solution is to check the OS version prior calling corresponding
function.
Since apr_file_lock uses only apr_file_t as function param, I've added
apr_oslevel_e type to the apr_file_t struct, and get it set during
apr_file_open. I've done that for the performance reason to avoid calling
GetOsVersion during each file lock/unlock.
***FILEIO.H:
--- fileio.h.old Wed Jun 27 21:40:54 2001
+++ fileio.h Mon Aug 13 12:24:46 2001
@@ -190,7 +190,7 @@
int direction; // buffer being used for 0 = read, 1 = write
apr_off_t filePtr; // position in file of handle
apr_lock_t *mutex; // mutex semaphore, must be owned to access
the above fields
-
+ apr_oslevel_e os_level;
/* Pipe specific info */
};
CUT!
OPEN.C:
--- open.c.old Tue Jul 31 19:37:46 2001
+++ open.c Mon Aug 13 12:24:32 2001
@@ -301,7 +301,7 @@
(*new)->dataRead = 0;
(*new)->direction = 0;
(*new)->filePtr = 0;
-
+ (*new)->os_level = os_level;
apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), file_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
CUT!
FLOCK.C:
--- flock.c.old Tue Aug 7 20:34:46 2001
+++ flock.c Mon Aug 13 12:38:04 2001
@@ -69,9 +69,15 @@
* recognize this as a try-again situation
*/
/* Syntax is correct, len is passed for LengthLow and LengthHigh*/
+ if (thefile->os_level >= APR_WIN_NT)
+ {
if (!LockFileEx(thefile->filehand, flags, 0, len, len, &offset))
return apr_get_os_error();
-
+ }
+ else {
+ if (!LockFile(thefile->filehand, 0, 0, len, 0))
+ return apr_get_os_error();
+ }
return APR_SUCCESS;
}
@@ -82,8 +88,14 @@
memset (&offset, 0, sizeof(offset));
/* Syntax is correct, len is passed for LengthLow and LengthHigh*/
+ if (thefile->os_level >= APR_WIN_NT)
+ {
if (!UnlockFileEx(thefile->filehand, 0, len, len, &offset))
return apr_get_os_error();
-
+ }
+ else {
+ if (!UnlockFile(thefile->filehand, 0, 0, len, 0))
+ return apr_get_os_error();
+ }
return APR_SUCCESS;
}
CUT!
MT.
Re: [PATCH] apr_file_lock/unclock on WIN9X
Posted by Bill Stoddard <bi...@wstoddard.com>.
-1 on putting os_level in the apr_file_t. The call to apr_get_oslevel is cheap. We make
the Win32 system call only once. The result is saved in a static variable that is
retrieved on subsequent calls to apr_get_oslevel. Committing a change to use *LockFile
rather than *LockFileEx on Win 9x.
Bill
----- Original Message -----
From: "Mladen Turk" <mt...@mappingsoft.com>
To: "APR Dev List" <de...@apr.apache.org>
Sent: Monday, August 13, 2001 7:24 AM
Subject: [PATCH] apr_file_lock/unclock on WIN9X
> Hi all,
>
> The apr_file_lock uses the LockFileEx API function to lock the file which is
> unsupported on WIN9X platform, so as apr_file_unlock which uses
> UnlockFileEx.
>
> The solution is to check the OS version prior calling corresponding
> function.
> Since apr_file_lock uses only apr_file_t as function param, I've added
> apr_oslevel_e type to the apr_file_t struct, and get it set during
> apr_file_open. I've done that for the performance reason to avoid calling
> GetOsVersion during each file lock/unlock.
>
> ***FILEIO.H:
> --- fileio.h.old Wed Jun 27 21:40:54 2001
> +++ fileio.h Mon Aug 13 12:24:46 2001
> @@ -190,7 +190,7 @@
> int direction; // buffer being used for 0 = read, 1 = write
> apr_off_t filePtr; // position in file of handle
> apr_lock_t *mutex; // mutex semaphore, must be owned to access
> the above fields
> -
> + apr_oslevel_e os_level;
> /* Pipe specific info */
> };
> CUT!
> OPEN.C:
> --- open.c.old Tue Jul 31 19:37:46 2001
> +++ open.c Mon Aug 13 12:24:32 2001
> @@ -301,7 +301,7 @@
> (*new)->dataRead = 0;
> (*new)->direction = 0;
> (*new)->filePtr = 0;
> -
> + (*new)->os_level = os_level;
> apr_pool_cleanup_register((*new)->cntxt, (void *)(*new), file_cleanup,
> apr_pool_cleanup_null);
> return APR_SUCCESS;
> CUT!
> FLOCK.C:
> --- flock.c.old Tue Aug 7 20:34:46 2001
> +++ flock.c Mon Aug 13 12:38:04 2001
> @@ -69,9 +69,15 @@
> * recognize this as a try-again situation
> */
> /* Syntax is correct, len is passed for LengthLow and LengthHigh*/
> + if (thefile->os_level >= APR_WIN_NT)
> + {
> if (!LockFileEx(thefile->filehand, flags, 0, len, len, &offset))
> return apr_get_os_error();
> -
> + }
> + else {
> + if (!LockFile(thefile->filehand, 0, 0, len, 0))
> + return apr_get_os_error();
> + }
> return APR_SUCCESS;
> }
>
> @@ -82,8 +88,14 @@
>
> memset (&offset, 0, sizeof(offset));
> /* Syntax is correct, len is passed for LengthLow and LengthHigh*/
> + if (thefile->os_level >= APR_WIN_NT)
> + {
> if (!UnlockFileEx(thefile->filehand, 0, len, len, &offset))
> return apr_get_os_error();
> -
> + }
> + else {
> + if (!UnlockFile(thefile->filehand, 0, 0, len, 0))
> + return apr_get_os_error();
> + }
> return APR_SUCCESS;
> }
> CUT!
>
>
> MT.
>