aboutsummaryrefslogtreecommitdiff
path: root/libio/genops.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-07-24 04:22:05 +0000
committerUlrich Drepper <drepper@redhat.com>2001-07-24 04:22:05 +0000
commitbeafb7521f1ce231fa3ac799cdedd361b3469886 (patch)
tree46a7a5d6f8173cf7ce74f5fe99f9b70ceabf88d9 /libio/genops.c
parent3afd949152e8d72708f9f430855c6e71595df78b (diff)
downloadglibc-beafb7521f1ce231fa3ac799cdedd361b3469886.zip
glibc-beafb7521f1ce231fa3ac799cdedd361b3469886.tar.gz
glibc-beafb7521f1ce231fa3ac799cdedd361b3469886.tar.bz2
Update.
* libio/iofclose.c (_IO_new_fclose): Unlink descriptor first to avoid deadlock. * libio/oldiofclose.c (_IO_old_fclose): Likewise. * libio/genops.c (_IO_un_link): Get stream lock since it's not always done in the caller. (_IO_link_in): Likewise.
Diffstat (limited to 'libio/genops.c')
-rw-r--r--libio/genops.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/libio/genops.c b/libio/genops.c
index b878b63..28bb0f9 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -40,6 +40,17 @@ static _IO_lock_t list_all_lock = _IO_lock_initializer;
/* Used to signal modifications to the list of FILE decriptors. */
static int _IO_list_all_stamp;
+
+static _IO_FILE *run_fp;
+
+static void
+flush_cleanup (void *not_used)
+{
+ if (run_fp != NULL)
+ _IO_funlockfile (run_fp);
+ _IO_lock_unlock (list_all_lock);
+}
+
void
_IO_un_link (fp)
struct _IO_FILE_plus *fp;
@@ -48,7 +59,10 @@ _IO_un_link (fp)
{
struct _IO_FILE_plus **f;
#ifdef _IO_MTSAFE_IO
+ _IO_cleanup_region_start_noarg (flush_cleanup);
_IO_lock_lock (list_all_lock);
+ run_fp = (_IO_FILE *) fp;
+ _IO_flockfile ((_IO_FILE *) fp);
#endif
for (f = &_IO_list_all; *f; f = (struct _IO_FILE_plus **) &(*f)->file._chain)
{
@@ -59,10 +73,13 @@ _IO_un_link (fp)
break;
}
}
+ fp->file._flags &= ~_IO_LINKED;
#ifdef _IO_MTSAFE_IO
+ _IO_funlockfile ((_IO_FILE *) fp);
+ run_fp = NULL;
_IO_lock_unlock (list_all_lock);
+ _IO_cleanup_region_end (0);
#endif
- fp->file._flags &= ~_IO_LINKED;
}
}
@@ -70,19 +87,25 @@ void
_IO_link_in (fp)
struct _IO_FILE_plus *fp;
{
- if ((fp->file._flags & _IO_LINKED) == 0)
- {
- fp->file._flags |= _IO_LINKED;
+ if ((fp->file._flags & _IO_LINKED) == 0)
+ {
+ fp->file._flags |= _IO_LINKED;
#ifdef _IO_MTSAFE_IO
- _IO_lock_lock (list_all_lock);
+ _IO_cleanup_region_start_noarg (flush_cleanup);
+ _IO_lock_lock (list_all_lock);
+ run_fp = (_IO_FILE *) fp;
+ _IO_flockfile ((_IO_FILE *) fp);
#endif
- fp->file._chain = (_IO_FILE *) _IO_list_all;
- _IO_list_all = fp;
- ++_IO_list_all_stamp;
+ fp->file._chain = (_IO_FILE *) _IO_list_all;
+ _IO_list_all = fp;
+ ++_IO_list_all_stamp;
#ifdef _IO_MTSAFE_IO
- _IO_lock_unlock (list_all_lock);
+ _IO_funlockfile ((_IO_FILE *) fp);
+ run_fp = NULL;
+ _IO_lock_unlock (list_all_lock);
+ _IO_cleanup_region_end (0);
#endif
- }
+ }
}
/* Return minimum _pos markers
@@ -756,17 +779,6 @@ _IO_get_column (fp)
#endif
-static _IO_FILE *run_fp;
-
-static void
-flush_cleanup (void *not_used)
-{
- if (run_fp != NULL)
- _IO_funlockfile (run_fp);
- _IO_lock_unlock (list_all_lock);
-}
-
-
int
_IO_flush_all ()
{