summaryrefslogtreecommitdiff
path: root/file_io/unix
diff options
context:
space:
mode:
authorbojan <bojan@13f79535-47bb-0310-9956-ffa450edef68>2007-05-14 22:58:16 +0000
committerbojan <bojan@13f79535-47bb-0310-9956-ffa450edef68>2007-05-14 22:58:16 +0000
commitc3d7be32f221dcf8c7f94d0c66845105c1d17cb1 (patch)
treea4be078a99bc66471f14a5450900f69e8c3ca669 /file_io/unix
parenta7a5083ebcbdd2220519c73ea4324973a7c79ee6 (diff)
downloadlibapr-c3d7be32f221dcf8c7f94d0c66845105c1d17cb1.tar.gz
Revert nested mutexes in Unix file_io
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@538009 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix')
-rw-r--r--file_io/unix/buffer.c2
-rw-r--r--file_io/unix/filedup.c4
-rw-r--r--file_io/unix/filestat.c22
-rw-r--r--file_io/unix/open.c4
-rw-r--r--file_io/unix/readwrite.c51
-rw-r--r--file_io/unix/seek.c4
6 files changed, 59 insertions, 28 deletions
diff --git a/file_io/unix/buffer.c b/file_io/unix/buffer.c
index cc8474fbe..ba2a8a7c6 100644
--- a/file_io/unix/buffer.c
+++ b/file_io/unix/buffer.c
@@ -28,7 +28,7 @@ APR_DECLARE(apr_status_t) apr_file_buffer_set(apr_file_t *file,
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;
diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c
index 3b40eab8c..d7a5d7775 100644
--- a/file_io/unix/filedup.c
+++ b/file_io/unix/filedup.c
@@ -55,7 +55,7 @@ static apr_status_t file_dup(apr_file_t **new_file,
#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 @@ APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file,
#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 */
diff --git a/file_io/unix/filestat.c b/file_io/unix/filestat.c
index 98ef74ec7..dd8b3adf9 100644
--- a/file_io/unix/filestat.c
+++ b/file_io/unix/filestat.c
@@ -100,6 +100,28 @@ static void fill_out_finfo(apr_finfo_t *finfo, struct_stat *info,
*/
}
+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)
diff --git a/file_io/unix/open.c b/file_io/unix/open.c
index 6a712a842..d1a3def34 100644
--- a/file_io/unix/open.c
+++ b/file_io/unix/open.c
@@ -122,7 +122,7 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new,
#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 @@ APR_DECLARE(apr_status_t) apr_os_file_put(apr_file_t **file,
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;
}
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index 6936519fc..83d849756 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -34,7 +34,7 @@ static apr_status_t file_read_buffered(apr_file_t *thefile, void *buf,
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 @@ APR_DECLARE(apr_status_t) apr_file_write(apr_file_t *thefile, const void *buf, a
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_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iove
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 @@ APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iove
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 @@ APR_DECLARE(apr_status_t) apr_file_writev(apr_file_t *thefile, const struct iove
*nbytes = bytes;
rv = APR_SUCCESS;
}
-
- file_unlock(thefile);
return rv;
#else
/**
@@ -306,25 +306,34 @@ APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile)
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 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
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;
diff --git a/file_io/unix/seek.c b/file_io/unix/seek.c
index 3e7e33ee4..34bb2a55f 100644
--- a/file_io/unix/seek.c
+++ b/file_io/unix/seek.c
@@ -22,7 +22,7 @@ static apr_status_t setptr(apr_file_t *thefile, apr_off_t pos )
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 @@ APR_DECLARE(apr_status_t) apr_file_seek(apr_file_t *thefile, apr_seek_where_t wh
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;