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 00:58:17 UTC
svn commit: r538009 - in /apr/apr/trunk: file_io/unix/buffer.c
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 15:58:16 2007
New Revision: 538009
URL: http://svn.apache.org/viewvc?view=rev&rev=538009
Log:
Revert nested mutexes in Unix file_io
Modified:
apr/apr/trunk/file_io/unix/buffer.c
apr/apr/trunk/file_io/unix/filedup.c
apr/apr/trunk/file_io/unix/filestat.c
apr/apr/trunk/file_io/unix/open.c
apr/apr/trunk/file_io/unix/readwrite.c
apr/apr/trunk/file_io/unix/seek.c
apr/apr/trunk/include/arch/unix/apr_arch_file_io.h
Modified: apr/apr/trunk/file_io/unix/buffer.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/buffer.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/buffer.c (original)
+++ apr/apr/trunk/file_io/unix/buffer.c Mon May 14 15:58:16 2007
@@ -28,7 +28,7 @@
if(file->buffered) {
/* Flush the existing buffer */
- rv = apr_file_flush(file);
+ rv = apr_file_flush_locked(file);
if (rv != APR_SUCCESS) {
file_unlock(file);
return rv;
Modified: apr/apr/trunk/file_io/unix/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/filedup.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/filedup.c (original)
+++ apr/apr/trunk/file_io/unix/filedup.c Mon May 14 15:58:16 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
@@ -133,7 +133,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/trunk/file_io/unix/filestat.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/filestat.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/filestat.c (original)
+++ apr/apr/trunk/file_io/unix/filestat.c Mon May 14 15:58:16 2007
@@ -100,6 +100,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/trunk/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/open.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/open.c (original)
+++ apr/apr/trunk/file_io/unix/open.c Mon May 14 15:58:16 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;
}
@@ -246,7 +246,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/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/readwrite.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Mon May 14 15:58:16 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 == thefile->bufsize) /* write buffer is full*/
- rv = apr_file_flush(thefile);
+ rv = apr_file_flush_locked(thefile);
blocksize = size > thefile->bufsize - thefile->bufpos ?
thefile->bufsize - thefile->bufpos : size;
@@ -230,10 +230,10 @@
apr_status_t rv;
apr_ssize_t bytes;
- file_lock(thefile);
-
if (thefile->buffered) {
- rv = apr_file_flush(thefile);
+ file_lock(thefile);
+
+ 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_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;
- }
- }
+ rv = apr_file_flush_locked(thefile);
file_unlock(thefile);
}
/* There isn't anything to do if we aren't buffering the output
@@ -353,7 +362,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/trunk/file_io/unix/seek.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/seek.c?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/file_io/unix/seek.c (original)
+++ apr/apr/trunk/file_io/unix/seek.c Mon May 14 15:58:16 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;
Modified: apr/apr/trunk/include/arch/unix/apr_arch_file_io.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_file_io.h?view=diff&rev=538009&r1=538008&r2=538009
==============================================================================
--- apr/apr/trunk/include/arch/unix/apr_arch_file_io.h (original)
+++ apr/apr/trunk/include/arch/unix/apr_arch_file_io.h Mon May 14 15:58:16 2007
@@ -160,6 +160,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 */