diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2025-03-05 00:23:05 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2025-03-05 00:37:08 +0100 |
commit | aad9ff97ff277fae87870faed8d0ec263079e040 (patch) | |
tree | be3132737156b18353a01b5251b2375ff879f79f | |
parent | c850aa60f945079f5a486cd9ca2a6ab723f6e094 (diff) |
libpipe: Introduce pipe_wait_writable_amount
-rw-r--r-- | libpipe/pipe.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/libpipe/pipe.h b/libpipe/pipe.h index f724e98b..ca9a6874 100644 --- a/libpipe/pipe.h +++ b/libpipe/pipe.h @@ -129,6 +129,8 @@ extern error_t pipe_wait_readable (struct pipe *pipe, int noblock, int data_only extern error_t pipe_select_readable (struct pipe *pipe, struct timespec *tsp, int data_only); +extern error_t pipe_wait_writable_amount (struct pipe *pipe, int noblock, size_t amount); + extern error_t pipe_wait_writable (struct pipe *pipe, int noblock); extern error_t pipe_select_writable (struct pipe *pipe, struct timespec *tsp); @@ -202,15 +204,15 @@ pipe_select_readable (struct pipe *pipe, struct timespec *tsp, int data_only) return err; } -/* Block until data can be written to PIPE. If NOBLOCK is true, then - EWOULDBLOCK is returned instead of blocking if this can't be done +/* Block until at least AMOUNT data can be written to PIPE. If NOBLOCK is true, + then EWOULDBLOCK is returned instead of blocking if this can't be done immediately. */ PIPE_EI error_t -pipe_wait_writable (struct pipe *pipe, int noblock) +pipe_wait_writable_amount (struct pipe *pipe, int noblock, size_t amount) { if (pipe->flags & PIPE_BROKEN) return EPIPE; - while (pipe_readable (pipe, 1) >= pipe->write_limit) + while (pipe_readable (pipe, 1) + amount >= pipe->write_limit) { if (noblock) return EWOULDBLOCK; @@ -222,6 +224,15 @@ pipe_wait_writable (struct pipe *pipe, int noblock) return 0; } +/* Block until data can be written to PIPE. If NOBLOCK is true, then + EWOULDBLOCK is returned instead of blocking if this can't be done + immediately. */ +PIPE_EI error_t +pipe_wait_writable (struct pipe *pipe, int noblock) +{ + return pipe_wait_writable_amount (pipe, noblock, 1); +} + /* Block until some data can be written to PIPE. This call only returns once threads waiting using pipe_wait_writable have been woken and given a chance to write, and if there is still space available thereafter. */ |