diff options
author | ivan <ivan@13f79535-47bb-0310-9956-ffa450edef68> | 2022-06-30 17:56:20 +0000 |
---|---|---|
committer | ivan <ivan@13f79535-47bb-0310-9956-ffa450edef68> | 2022-06-30 17:56:20 +0000 |
commit | 79ce54ccbc6f75b48575685ba6ba0103ef483a66 (patch) | |
tree | 5955e7d0379df297cb76ee6a8c29e26a7bedc1df | |
parent | 8a5cac39bdecb616d402a5e820b6fc64aa951762 (diff) | |
download | libapr-79ce54ccbc6f75b48575685ba6ba0103ef483a66.tar.gz |
On 1.8.x branch: Merge r1808457 from trunk:
Win32: Create and use file mutex only for files opened with APR_FOPEN_XTHREAD.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1902380 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | file_io/win32/open.c | 7 | ||||
-rw-r--r-- | file_io/win32/readwrite.c | 26 |
2 files changed, 20 insertions, 13 deletions
diff --git a/file_io/win32/open.c b/file_io/win32/open.c index f1a46286d..b6c01432e 100644 --- a/file_io/win32/open.c +++ b/file_io/win32/open.c @@ -451,8 +451,8 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, const char *fname, (*new)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*new)->bufsize = APR_FILE_DEFAULT_BUFSIZE; } - /* Need the mutex to handled buffered and O_APPEND style file i/o */ - if ((*new)->buffered || (*new)->append) { + /* Need the mutex to share an apr_file_t across multiple threads */ + if (flag & APR_FOPEN_XTHREAD) { rv = apr_thread_mutex_create(&(*new)->mutex, APR_THREAD_MUTEX_DEFAULT, pool); if (rv) { @@ -644,8 +644,7 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file, (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE); (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE; } - - if ((*file)->append || (*file)->buffered) { + if (flags & APR_FOPEN_XTHREAD) { apr_status_t rv; rv = apr_thread_mutex_create(&(*file)->mutex, APR_THREAD_MUTEX_DEFAULT, pool); diff --git a/file_io/win32/readwrite.c b/file_io/win32/readwrite.c index 027ef988d..77bb5795b 100644 --- a/file_io/win32/readwrite.c +++ b/file_io/win32/readwrite.c @@ -436,20 +436,26 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a apr_off_t offset = 0; apr_status_t rc; if (thefile->append) { - /* apr_file_lock will mutex the file across processes. - * The call to apr_thread_mutex_lock is added to avoid - * a race condition between LockFile and WriteFile - * that occasionally leads to deadlocked threads. - */ - apr_thread_mutex_lock(thefile->mutex); + if (thefile->flags & APR_FOPEN_XTHREAD) { + /* apr_file_lock will mutex the file across processes. + * The call to apr_thread_mutex_lock is added to avoid + * a race condition between LockFile and WriteFile + * that occasionally leads to deadlocked threads. + */ + apr_thread_mutex_lock(thefile->mutex); + } rc = apr_file_lock(thefile, APR_FLOCK_EXCLUSIVE); if (rc != APR_SUCCESS) { - apr_thread_mutex_unlock(thefile->mutex); + if (thefile->flags & APR_FOPEN_XTHREAD) { + apr_thread_mutex_unlock(thefile->mutex); + } return rc; } rc = apr_file_seek(thefile, APR_END, &offset); if (rc != APR_SUCCESS) { - apr_thread_mutex_unlock(thefile->mutex); + if (thefile->flags & APR_FOPEN_XTHREAD) { + apr_thread_mutex_unlock(thefile->mutex); + } return rc; } } @@ -461,7 +467,9 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a thefile->pOverlapped); if (thefile->append) { apr_file_unlock(thefile); - apr_thread_mutex_unlock(thefile->mutex); + if (thefile->flags & APR_FOPEN_XTHREAD) { + apr_thread_mutex_unlock(thefile->mutex); + } } } if (rv) { |