summaryrefslogtreecommitdiff
path: root/libpipe
diff options
context:
space:
mode:
Diffstat (limited to 'libpipe')
-rw-r--r--libpipe/pipe.c31
-rw-r--r--libpipe/pipe.h4
2 files changed, 23 insertions, 12 deletions
diff --git a/libpipe/pipe.c b/libpipe/pipe.c
index 1d4f5cc0..8ffc56e9 100644
--- a/libpipe/pipe.c
+++ b/libpipe/pipe.c
@@ -200,6 +200,24 @@ void _pipe_no_writers (struct pipe *pipe)
pthread_mutex_unlock (&pipe->lock);
}
}
+
+/* Take any actions necessary when PIPE's writer can proceed.
+ PIPE should be locked. */
+void _pipe_wake_writers (struct pipe *pipe)
+{
+ pthread_cond_broadcast (&pipe->pending_writes);
+ pthread_mutex_unlock (&pipe->lock);
+
+ pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
+ /* Only wakeup selects if there's still writing space available. */
+ if (pipe_readable (pipe, 1) < pipe->write_limit)
+ {
+ pthread_cond_broadcast (&pipe->pending_write_selects);
+ pipe_select_cond_broadcast (pipe);
+ /* We leave PIPE locked here, assuming the caller will soon unlock
+ it and allow others access. */
+ }
+}
/* Return when either RPIPE is available for reading (if SELECT_READ is set
in *SELECT_TYPE), or WPIPE is available for writing (if select_write is
@@ -474,18 +492,7 @@ pipe_recv (struct pipe *pipe, int noblock, unsigned *flags, void **source,
timestamp (&pipe->read_time);
/* And wakeup anyone that might be interested in it. */
- pthread_cond_broadcast (&pipe->pending_writes);
- pthread_mutex_unlock (&pipe->lock);
-
- pthread_mutex_lock (&pipe->lock); /* Get back the lock on PIPE. */
- /* Only wakeup selects if there's still writing space available. */
- if (pipe_readable (pipe, 1) < pipe->write_limit)
- {
- pthread_cond_broadcast (&pipe->pending_write_selects);
- pipe_select_cond_broadcast (pipe);
- /* We leave PIPE locked here, assuming the caller will soon unlock
- it and allow others access. */
- }
+ _pipe_wake_writers (pipe);
}
return err;
diff --git a/libpipe/pipe.h b/libpipe/pipe.h
index 040204d5..eda38d24 100644
--- a/libpipe/pipe.h
+++ b/libpipe/pipe.h
@@ -263,6 +263,10 @@ void _pipe_no_readers (struct pipe *pipe);
should be locked. */
void _pipe_no_writers (struct pipe *pipe);
+/* Take any actions necessary when PIPE's writer can proceed.
+ PIPE should be locked. */
+void _pipe_wake_writers (struct pipe *pipe);
+
extern void pipe_acquire_reader (struct pipe *pipe);
extern void pipe_acquire_writer (struct pipe *pipe);