summaryrefslogtreecommitdiff
path: root/libpipe
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-08-15 17:48:15 +0000
committerMiles Bader <miles@gnu.org>1995-08-15 17:48:15 +0000
commita9e502ede9ab14c5d6e4af4d570e0fd514ad221d (patch)
tree2f1a836ff11d0cea86ce7af2a7e40d7c2408110b /libpipe
parent6c18a877843879c8cb7cf83d34a803e5310e6120 (diff)
(pipe_create): Initialize READERS & WRITERS, not REFS.
(_pipe_first_writer): New function. (_pipe_no_writers, _pipe_no_writers): New function. (pipe_break): Function deleted.
Diffstat (limited to 'libpipe')
-rw-r--r--libpipe/pipe.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/libpipe/pipe.c b/libpipe/pipe.c
index a81bdcdc..413b4ec2 100644
--- a/libpipe/pipe.c
+++ b/libpipe/pipe.c
@@ -43,7 +43,8 @@ pipe_create (struct pipe_class *class, struct pipe **pipe)
if (new == NULL)
return ENOMEM;
- new->refs = 0;
+ new->readers = 0;
+ new->writers = 0;
new->flags = 0;
new->class = class;
@@ -68,7 +69,7 @@ pipe_free (struct pipe *pipe)
pq_free (pipe->queue);
free (pipe);
}
-
+
/* Wake up all threads waiting on PIPE, which should be locked. */
inline void
pipe_kick (struct pipe *pipe)
@@ -80,23 +81,40 @@ pipe_kick (struct pipe *pipe)
mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
}
-/* Discard a reference to PIPE, which should be unlocked, being sure to make
- users aware of this. */
-void
-pipe_break (struct pipe *pipe)
+/* Take any actions necessary when PIPE aquires its first writer. */
+void _pipe_first_writer (struct pipe *pipe)
{
- mutex_lock (&pipe->lock);
-
- /* As there may be multiple writers on a connectionless socket, we
- never allow EOF to be signaled on the reader. */
if (! (pipe->class->flags & PIPE_CLASS_CONNECTIONLESS))
- pipe->flags |= PIPE_BROKEN;
+ pipe->flags &= ~PIPE_BROKEN;
+}
- if (pipe->refs > 1)
- /* Other references to PIPE besides ours? Wake 'em up. */
- pipe_kick (pipe);
+/* Take any actions necessary when PIPE's last reader has gone away. PIPE
+ should be locked. */
+void _pipe_no_readers (struct pipe *pipe)
+{
+ if (pipe->writers == 0)
+ pipe_free (pipe);
+ else
+ mutex_unlock (&pipe->lock);
+}
- pipe_release (pipe);
+/* Take any actions necessary when PIPE's last writer has gone away. PIPE
+ should be locked. */
+void _pipe_no_writers (struct pipe *pipe)
+{
+ if (pipe->readers == 0)
+ pipe_free (pipe);
+ else
+ {
+ if (! (pipe->class->flags & PIPE_CLASS_CONNECTIONLESS))
+ {
+ pipe->flags |= PIPE_BROKEN;
+ if (pipe->readers)
+ /* Wake up readers who might want to know about our new state. */
+ pipe_kick (pipe);
+ }
+ mutex_unlock (&pipe->lock);
+ }
}
/* Writes up to LEN bytes of DATA, to PIPE, which should be locked, and