Skip to content

Commit

Permalink
buffer: Pass timeout parameter
Browse files Browse the repository at this point in the history
This is a preparation to check the buffer contents without waiting.
  • Loading branch information
namhyung authored and wkz committed Sep 29, 2021
1 parent 9b8438c commit b15240d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/ply/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ struct buffer;

struct buffer *buffer_new(int mapfd);

struct ply_return buffer_loop(struct buffer *buf);
struct ply_return buffer_loop(struct buffer *buf, int timeout);

#endif /* _PLY_BUFFER_H */
11 changes: 8 additions & 3 deletions src/libply/built-in/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,26 @@ struct ply_return buffer_q_drain(struct buffer_q *q)
return ret;
}

struct ply_return buffer_loop(struct buffer *buf)
struct ply_return buffer_loop(struct buffer *buf, int timeout)
{
struct ply_return ret;
uint32_t cpu;
int ready;

for (;;) {
ready = poll(buf->poll, buf->ncpus, -1);
ready = poll(buf->poll, buf->ncpus, timeout);
if (ready < 0) {
ret.err = 1;
ret.val = errno;
return ret;
}

assert(ready);
if (timeout == -1) {
assert(ready);
} else if (ready == 0) {
ret.err = 0;
return ret;
}

for (cpu = 0; ready && (cpu < buf->ncpus); cpu++) {
if (!(buf->poll[cpu].revents & POLLIN))
Expand Down
2 changes: 1 addition & 1 deletion src/libply/libply.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ struct ply_return ply_loop(struct ply *ply)
return (struct ply_return){ .err = 1, .val = EINTR };
}

return buffer_loop((struct buffer *)ply->stdbuf->priv);
return buffer_loop((struct buffer *)ply->stdbuf->priv, -1);
}

int ply_stop(struct ply *ply)
Expand Down

0 comments on commit b15240d

Please sign in to comment.