apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r929070 - in /apr/apr/trunk/file_io/os2: buffer.c open.c readwrite.c
Date Tue, 30 Mar 2010 10:35:43 GMT
Author: bjh
Date: Tue Mar 30 10:35:43 2010
New Revision: 929070

URL: http://svn.apache.org/viewvc?rev=929070&view=rev
Log:
OS/2: Only mutex protect buffer access if APR_FOPEN_XTHREAD is specified.
Also add missing mutex locking in apr_file_flush().

Modified:
    apr/apr/trunk/file_io/os2/buffer.c
    apr/apr/trunk/file_io/os2/open.c
    apr/apr/trunk/file_io/os2/readwrite.c

Modified: apr/apr/trunk/file_io/os2/buffer.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/buffer.c?rev=929070&r1=929069&r2=929070&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/buffer.c (original)
+++ apr/apr/trunk/file_io/os2/buffer.c Tue Mar 30 10:35:43 2010
@@ -22,35 +22,45 @@ APR_DECLARE(apr_status_t) apr_file_buffe
                                               apr_size_t bufsize)
 {
     apr_status_t rv;
+    int do_locking = file->mutex != NULL && file->buffered;
 
-    apr_thread_mutex_lock(file->mutex);
+    if (do_locking) {
+        apr_thread_mutex_lock(file->mutex);
+    }
  
-    if(file->buffered) {
+    if (file->buffered) {
         /* Flush the existing buffer */
         rv = apr_file_flush(file);
         if (rv != APR_SUCCESS) {
-            apr_thread_mutex_unlock(file->mutex);
+            if (do_locking) {
+                apr_thread_mutex_unlock(file->mutex);
+            }
+
             return rv;
         }
     }
         
     file->buffer = buffer;
     file->bufsize = bufsize;
-    file->buffered = 1;
     file->bufpos = 0;
     file->direction = 0;
     file->dataRead = 0;
- 
-    if (file->bufsize == 0) {
-            /* Setting the buffer size to zero is equivalent to turning 
-             * buffering off. 
-             */
-            file->buffered = 0;
+
+    if (bufsize > 0 && file->mutex == NULL && (file->flags &
APR_FOPEN_XTHREAD)) {
+        /* buffering is being turned on but we have no mutex, make one */
+        rv = apr_thread_mutex_create(&file->mutex, 0, file->pool);
     }
+
+    /* Setting the buffer size to zero is equivalent to turning 
+     * buffering off. 
+     */
+    file->buffered = file->bufsize > 0;
     
-    apr_thread_mutex_unlock(file->mutex);
+    if (do_locking) {
+        apr_thread_mutex_unlock(file->mutex);
+    }
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 APR_DECLARE(apr_size_t) apr_file_buffer_size_get(apr_file_t *file)

Modified: apr/apr/trunk/file_io/os2/open.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/open.c?rev=929070&r1=929069&r2=929070&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/open.c (original)
+++ apr/apr/trunk/file_io/os2/open.c Tue Mar 30 10:35:43 2010
@@ -36,7 +36,7 @@ APR_DECLARE(apr_status_t) apr_file_open(
     int mflags = OPEN_FLAGS_FAIL_ON_ERROR|OPEN_SHARE_DENYNONE|OPEN_FLAGS_NOINHERIT;
     int rv;
     ULONG action;
-    apr_file_t *dafile = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));
+    apr_file_t *dafile = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
 
     dafile->pool = pool;
     dafile->isopen = FALSE;
@@ -61,10 +61,14 @@ APR_DECLARE(apr_status_t) apr_file_open(
     if (dafile->buffered) {
         dafile->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);
         dafile->bufsize = APR_FILE_DEFAULT_BUFSIZE;
-        rv = apr_thread_mutex_create(&dafile->mutex, 0, pool);
 
-        if (rv)
-            return rv;
+        if (flag & APR_FOPEN_XTHREAD) {
+            rv = apr_thread_mutex_create(&dafile->mutex, 0, pool);
+
+            if (rv) {
+                return rv;
+            }
+        }
     }
 
     if (flag & APR_FOPEN_CREATE) {

Modified: apr/apr/trunk/file_io/os2/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/readwrite.c?rev=929070&r1=929069&r2=929070&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/readwrite.c (original)
+++ apr/apr/trunk/file_io/os2/readwrite.c Tue Mar 30 10:35:43 2010
@@ -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(
         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(
         }
 
         *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
         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
             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
         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);



Mime
View raw message