Support fswait in (unix) pipes

This commit is contained in:
Kevin Lange 2017-01-14 12:00:46 +09:00
parent 8a35ee463a
commit 8fc3c07f4b

View File

@ -93,6 +93,21 @@ static void close_write_pipe(fs_node_t * node) {
}
}
static int check_pipe(fs_node_t * node) {
struct unix_pipe * self = node->device;
if (ring_buffer_unread(self->buffer) > 0) {
return 0;
}
return 1;
}
static int wait_pipe(fs_node_t * node, void * process) {
struct unix_pipe * self = node->device;
ring_buffer_select_wait(self->buffer, process);
return 0;
}
int make_unix_pipe(fs_node_t ** pipes) {
size_t size = UNIX_PIPE_BUFFER;
@ -117,6 +132,10 @@ int make_unix_pipe(fs_node_t ** pipes) {
pipes[0]->close = close_read_pipe;
pipes[1]->close = close_write_pipe;
/* Read end can wait */
pipes[0]->selectcheck = check_pipe;
pipes[0]->selectwait = wait_pipe;
struct unix_pipe * internals = malloc(sizeof(struct unix_pipe));
internals->read_end = pipes[0];
internals->write_end = pipes[1];