apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r538034 - in /apr/apr/branches/0.9.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
Date Tue, 15 May 2007 01:24:03 GMT
Author: bojan
Date: Mon May 14 18:24:02 2007
New Revision: 538034

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

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

Modified: apr/apr/branches/0.9.x/file_io/unix/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/filedup.c?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/filedup.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/filedup.c Mon May 14 18:24:02 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
@@ -126,7 +126,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/0.9.x/file_io/unix/filestat.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/filestat.c?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/filestat.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/filestat.c Mon May 14 18:24:02 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/0.9.x/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/open.c?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/open.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/open.c Mon May 14 18:24:02 2007
@@ -108,7 +108,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;
         }
@@ -218,7 +218,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/0.9.x/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/readwrite.c?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/readwrite.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/readwrite.c Mon May 14 18:24:02 2007
@@ -46,7 +46,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;
@@ -167,7 +167,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;
@@ -228,10 +228,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;
@@ -246,6 +246,8 @@
                 lseek(thefile->filedes, offset, SEEK_SET);
             thefile->bufpos = thefile->dataRead = 0;
         }
+
+        file_unlock(thefile);
     }
 
     if ((bytes = writev(thefile->filedes, vec, nvec)) < 0) {
@@ -256,8 +258,6 @@
         *nbytes = bytes;
         rv = APR_SUCCESS;
     }
-
-    file_unlock(thefile);
     return rv;
 #else
     *nbytes = vec[0].iov_len;
@@ -292,25 +292,34 @@
     return apr_file_write(thefile, str, &nbytes);
 }
 
+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

Modified: apr/apr/branches/0.9.x/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/file_io/unix/seek.c?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/file_io/unix/seek.c (original)
+++ apr/apr/branches/0.9.x/file_io/unix/seek.c Mon May 14 18:24:02 2007
@@ -18,33 +18,34 @@
 
 static apr_status_t setptr(apr_file_t *thefile, unsigned long pos )
 {
-    long newbufpos;
-    int rc;
+    apr_off_t newbufpos;
+    apr_status_t rv;
 
     if (thefile->direction == 1) {
-        apr_file_flush(thefile);
+        rv = apr_file_flush_locked(thefile);
+        if (rv) {
+            return rv;
+        }
         thefile->bufpos = thefile->direction = thefile->dataRead = 0;
     }
 
     newbufpos = pos - (thefile->filePtr - thefile->dataRead);
     if (newbufpos >= 0 && newbufpos <= thefile->dataRead) {
         thefile->bufpos = newbufpos;
-        rc = 0;
-    } 
+        rv = APR_SUCCESS;
+    }
     else {
-        rc = lseek(thefile->filedes, pos, SEEK_SET);
-
-        if (rc != -1 ) {
+        if (lseek(thefile->filedes, pos, SEEK_SET) != -1) {
             thefile->bufpos = thefile->dataRead = 0;
             thefile->filePtr = pos;
-            rc = 0;
+            rv = APR_SUCCESS;
         }
         else {
-            rc = errno;
+            rv = errno;
         }
     }
 
-    return rc;
+    return rv;
 }
 
 
@@ -70,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;
@@ -100,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/0.9.x/include/arch/unix/apr_arch_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/include/arch/unix/apr_arch_file_io.h?view=diff&rev=538034&r1=538033&r2=538034
==============================================================================
--- apr/apr/branches/0.9.x/include/arch/unix/apr_arch_file_io.h (original)
+++ apr/apr/branches/0.9.x/include/arch/unix/apr_arch_file_io.h Mon May 14 18:24:02 2007
@@ -130,6 +130,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 */
 



Mime
View raw message