You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2007/05/15 02:36:41 UTC

svn commit: r538029 - in /apr/apr/branches/1.2.x: file_io/unix/filedup.c file_io/unix/filestat.c file_io/unix/open.c file_io/unix/readwrite.c file_io/unix/seek.c include/arch/unix/apr_arch_file_io.h

Author: bojan
Date: Mon May 14 17:36:40 2007
New Revision: 538029

URL: http://svn.apache.org/viewvc?view=rev&rev=538029
Log:
Backport r538009 and r538019 from the trunk.
Revert nested mutexes in Unix file_io.

Modified:
    apr/apr/branches/1.2.x/file_io/unix/filedup.c
    apr/apr/branches/1.2.x/file_io/unix/filestat.c
    apr/apr/branches/1.2.x/file_io/unix/open.c
    apr/apr/branches/1.2.x/file_io/unix/readwrite.c
    apr/apr/branches/1.2.x/file_io/unix/seek.c
    apr/apr/branches/1.2.x/include/arch/unix/apr_arch_file_io.h

Modified: apr/apr/branches/1.2.x/file_io/unix/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/file_io/unix/filedup.c?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/filedup.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/filedup.c Mon May 14 17:36:40 2007
@@ -55,7 +55,7 @@
 #if APR_HAS_THREADS
     if ((*new_file)->buffered && !(*new_file)->thlock && old_file->thlock) {
         apr_thread_mutex_create(&((*new_file)->thlock),
-                                APR_THREAD_MUTEX_NESTED, p);
+                                APR_THREAD_MUTEX_DEFAULT, p);
     }
 #endif
     /* As above, only create the buffer if we haven't already
@@ -131,7 +131,7 @@
 #if APR_HAS_THREADS
         if (old_file->thlock) {
             apr_thread_mutex_create(&((*new_file)->thlock),
-                                    APR_THREAD_MUTEX_NESTED, p);
+                                    APR_THREAD_MUTEX_DEFAULT, p);
             apr_thread_mutex_destroy(old_file->thlock);
         }
 #endif /* APR_HAS_THREADS */

Modified: apr/apr/branches/1.2.x/file_io/unix/filestat.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/file_io/unix/filestat.c?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/filestat.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/filestat.c Mon May 14 17:36:40 2007
@@ -91,6 +91,28 @@
      */
 }
 
+apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted,
+                                      apr_file_t *thefile)
+{
+    struct_stat info;
+
+    if (thefile->buffered) {
+        apr_status_t rv = apr_file_flush_locked(thefile);
+        if (rv != APR_SUCCESS)
+            return rv;
+    }
+
+    if (fstat(thefile->filedes, &info) == 0) {
+        finfo->pool = thefile->pool;
+        finfo->fname = thefile->fname;
+        fill_out_finfo(finfo, &info, wanted);
+        return (wanted & ~finfo->valid) ? APR_INCOMPLETE : APR_SUCCESS;
+    }
+    else {
+        return errno;
+    }
+}
+
 APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, 
                                             apr_int32_t wanted,
                                             apr_file_t *thefile)

Modified: apr/apr/branches/1.2.x/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/file_io/unix/open.c?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/open.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/open.c Mon May 14 17:36:40 2007
@@ -122,7 +122,7 @@
 #if APR_HAS_THREADS
     if ((flag & APR_BUFFERED) && (flag & APR_XTHREAD)) {
         rv = apr_thread_mutex_create(&thlock,
-                                     APR_THREAD_MUTEX_NESTED, pool);
+                                     APR_THREAD_MUTEX_DEFAULT, pool);
         if (rv) {
             return rv;
         }
@@ -244,7 +244,7 @@
         if ((*file)->flags & APR_XTHREAD) {
             apr_status_t rv;
             rv = apr_thread_mutex_create(&((*file)->thlock),
-                                         APR_THREAD_MUTEX_NESTED, pool);
+                                         APR_THREAD_MUTEX_DEFAULT, pool);
             if (rv) {
                 return rv;
             }

Modified: apr/apr/branches/1.2.x/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/file_io/unix/readwrite.c?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/readwrite.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/readwrite.c Mon May 14 17:36:40 2007
@@ -34,7 +34,7 @@
     apr_uint64_t size = *nbytes;
 
     if (thefile->direction == 1) {
-        rv = apr_file_flush(thefile);
+        rv = apr_file_flush_locked(thefile);
         if (rv) {
             return rv;
         }
@@ -169,7 +169,7 @@
         rv = 0;
         while (rv == 0 && size > 0) {
             if (thefile->bufpos == APR_FILE_BUFSIZE)   /* write buffer is full*/
-                rv = apr_file_flush(thefile);
+                rv = apr_file_flush_locked(thefile);
 
             blocksize = size > APR_FILE_BUFSIZE - thefile->bufpos ? 
                         APR_FILE_BUFSIZE - thefile->bufpos : size;
@@ -230,10 +230,10 @@
     apr_status_t rv;
     int bytes;
 
-    file_lock(thefile);
-
     if (thefile->buffered) {
-        apr_status_t rv = apr_file_flush(thefile);
+        file_lock(thefile);
+
+        apr_status_t rv = apr_file_flush_locked(thefile);
         if (rv != APR_SUCCESS) {
             file_unlock(thefile);
             return rv;
@@ -248,6 +248,8 @@
                 lseek(thefile->filedes, offset, SEEK_SET);
             thefile->bufpos = thefile->dataRead = 0;
         }
+
+        file_unlock(thefile);
     }
 
     if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
@@ -258,8 +260,6 @@
         *nbytes = bytes;
         rv = APR_SUCCESS;
     }
-
-    file_unlock(thefile);
     return rv;
 #else
     /**
@@ -306,25 +306,34 @@
     return apr_file_write_full(thefile, str, strlen(str), NULL);
 }
 
+apr_status_t apr_file_flush_locked(apr_file_t *thefile)
+{
+    apr_status_t rv = APR_SUCCESS;
+
+    if (thefile->direction == 1 && thefile->bufpos) {
+        apr_ssize_t written;
+
+        do {
+            written = write(thefile->filedes, thefile->buffer, thefile->bufpos);
+        } while (written == -1 && errno == EINTR);
+        if (written == -1) {
+            rv = errno;
+        } else {
+            thefile->filePtr += written;
+            thefile->bufpos = 0;
+        }
+    }
+
+    return rv;
+}
+
 APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile)
 {
     apr_status_t rv = APR_SUCCESS;
 
     if (thefile->buffered) {
         file_lock(thefile);
-
-        if (thefile->direction == 1 && thefile->bufpos) {
-            apr_int64_t written = 0;
-            do {
-                written = write(thefile->filedes, thefile->buffer, thefile->bufpos);
-            } while (written == (apr_int64_t)-1 && errno == EINTR);
-            if (written == (apr_int64_t)-1) {
-                rv = errno;
-            } else {
-                thefile->filePtr += written;
-                thefile->bufpos = 0;
-            }
-        }
+        rv = apr_file_flush_locked(thefile);
         file_unlock(thefile);
     }
     /* There isn't anything to do if we aren't buffering the output
@@ -354,7 +363,7 @@
         file_lock(thefile);
 
         if (thefile->direction == 1) {
-            rv = apr_file_flush(thefile);
+            rv = apr_file_flush_locked(thefile);
             if (rv) {
                 file_unlock(thefile);
                 return rv;

Modified: apr/apr/branches/1.2.x/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/file_io/unix/seek.c?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/seek.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/seek.c Mon May 14 17:36:40 2007
@@ -22,7 +22,7 @@
     apr_status_t rv;
 
     if (thefile->direction == 1) {
-        rv = apr_file_flush(thefile);
+        rv = apr_file_flush_locked(thefile);
         if (rv) {
             return rv;
         }
@@ -71,7 +71,7 @@
             break;
 
         case APR_END:
-            rc = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile);
+            rc = apr_file_info_get_locked(&finfo, APR_FINFO_SIZE, thefile);
             if (rc == APR_SUCCESS)
                 rc = setptr(thefile, finfo.size + *offset);
             break;
@@ -101,5 +101,5 @@
     if (ftruncate(fp->filedes, offset) == -1) {
         return errno;
     }
-    return setptr(fp, offset);
+    return apr_file_seek(fp, APR_SET, &offset);
 }

Modified: apr/apr/branches/1.2.x/include/arch/unix/apr_arch_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.2.x/include/arch/unix/apr_arch_file_io.h?view=diff&rev=538029&r1=538028&r2=538029
==============================================================================
--- apr/apr/branches/1.2.x/include/arch/unix/apr_arch_file_io.h (original)
+++ apr/apr/branches/1.2.x/include/arch/unix/apr_arch_file_io.h Mon May 14 17:36:40 2007
@@ -147,6 +147,10 @@
 mode_t apr_unix_perms2mode(apr_fileperms_t perms);
 apr_fileperms_t apr_unix_mode2perms(mode_t mode);
 
+apr_status_t apr_file_flush_locked(apr_file_t *thefile);
+apr_status_t apr_file_info_get_locked(apr_finfo_t *finfo, apr_int32_t wanted,
+                                      apr_file_t *thefile);
+
 
 #endif  /* ! FILE_IO_H */