aboutsummaryrefslogtreecommitdiff
path: root/file_io/os2/readwrite.c
diff options
context:
space:
mode:
authorBrian Havard <bjh@apache.org>2010-03-30 10:35:43 +0000
committerBrian Havard <bjh@apache.org>2010-03-30 10:35:43 +0000
commit2ea737c161153c38fa5f9c826b8bee5b961da8e3 (patch)
tree2872d30f5b4e22b9f9a6e5d53f70958f8dde48e8 /file_io/os2/readwrite.c
parent45b199ad97cd3404e9885aa178a3bd6afa20e043 (diff)
downloadapr-2ea737c161153c38fa5f9c826b8bee5b961da8e3.tar.gz
apr-2ea737c161153c38fa5f9c826b8bee5b961da8e3.zip
OS/2: Only mutex protect buffer access if APR_FOPEN_XTHREAD is specified.
Also add missing mutex locking in apr_file_flush(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@929070 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/os2/readwrite.c')
-rw-r--r--file_io/os2/readwrite.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/file_io/os2/readwrite.c b/file_io/os2/readwrite.c
index 9c44ee0e0..5dc0f9ad6 100644
--- a/file_io/os2/readwrite.c
+++ b/file_io/os2/readwrite.c
@@ -24,6 +24,24 @@
#include <malloc.h>
+static void file_lock(apr_file_t *thefile)
+{
+ if (thefile->mutex && thefile->buffered) {
+ apr_thread_mutex_lock(thefile->mutex);
+ }
+}
+
+
+
+static void file_unlock(apr_file_t *thefile)
+{
+ if (thefile->mutex && thefile->buffered) {
+ apr_thread_mutex_unlock(thefile->mutex);
+ }
+}
+
+
+
APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size_t *nbytes)
{
ULONG rc = 0;
@@ -39,13 +57,13 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size
ULONG blocksize;
ULONG size = *nbytes;
- apr_thread_mutex_lock(thefile->mutex);
+ file_lock(thefile);
if (thefile->direction == 1) {
int rv = apr_file_flush(thefile);
if (rv != APR_SUCCESS) {
- apr_thread_mutex_unlock(thefile->mutex);
+ file_unlock(thefile);
return rv;
}
@@ -79,7 +97,7 @@ APR_DECLARE(apr_status_t) apr_file_read(apr_file_t *thefile, void *buf, apr_size
}
*nbytes = rc == 0 ? pos - (char *)buf : 0;
- apr_thread_mutex_unlock(thefile->mutex);
+ file_unlock(thefile);
if (*nbytes == 0 && rc == 0 && thefile->eof_hit) {
return APR_EOF;
@@ -137,7 +155,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
int blocksize;
int size = *nbytes;
- apr_thread_mutex_lock(thefile->mutex);
+ file_lock(thefile);
if ( thefile->direction == 0 ) {
// Position file pointer for writing at the offset we are logically reading from
@@ -160,7 +178,7 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
size -= blocksize;
}
- apr_thread_mutex_unlock(thefile->mutex);
+ file_unlock(thefile);
return APR_FROM_OS_ERROR(rc);
} else {
if (thefile->flags & APR_FOPEN_APPEND) {
@@ -288,11 +306,15 @@ APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile)
int rc = 0;
if (thefile->direction == 1 && thefile->bufpos) {
+ file_lock(thefile);
+
rc = DosWrite(thefile->filedes, thefile->buffer, thefile->bufpos, &written);
thefile->filePtr += written;
if (rc == 0)
thefile->bufpos = 0;
+
+ file_unlock(thefile);
}
return APR_FROM_OS_ERROR(rc);