Commit 03e650aa authored by Max Kellermann's avatar Max Kellermann

main_notify: make the read side of the pipe blocking

Currently, both sides of the pipe are blocking, although we do not need blocking read(). Convert it back to blocking. Eliminate the select() from wait_main_task().
parent 10b5966b
...@@ -63,7 +63,12 @@ static int ioops_consume(int fd_count, fd_set * rfds, ...@@ -63,7 +63,12 @@ static int ioops_consume(int fd_count, fd_set * rfds,
void init_main_notify(void) void init_main_notify(void)
{ {
main_task = g_thread_self(); main_task = g_thread_self();
init_async_pipe(main_pipe);
if (pipe(main_pipe) < 0)
g_error("Couldn't open pipe: %s", strerror(errno));
if (set_nonblocking(main_pipe[1]) < 0)
g_error("Couldn't set non-blocking I/O: %s", strerror(errno));
main_notify_IO.fdset = ioops_fdset; main_notify_IO.fdset = ioops_fdset;
main_notify_IO.consume = ioops_consume; main_notify_IO.consume = ioops_consume;
registerIO(&main_notify_IO); registerIO(&main_notify_IO);
...@@ -96,19 +101,5 @@ void main_notify_unlock(void) ...@@ -96,19 +101,5 @@ void main_notify_unlock(void)
void wait_main_task(void) void wait_main_task(void)
{ {
fd_set rfds;
int ret;
assert(main_task == g_thread_self());
do {
FD_ZERO(&rfds);
FD_SET(main_pipe[0], &rfds);
ret = select(main_pipe[0] + 1, &rfds, NULL, NULL, NULL);
} while (ret == 0 || (ret < 0 && (errno == EAGAIN || errno == EINTR)));
if (ret < 0)
g_error("select() failed: %s", strerror(errno));
consume_pipe(); consume_pipe();
} }
...@@ -211,16 +211,6 @@ int set_nonblocking(int fd) ...@@ -211,16 +211,6 @@ int set_nonblocking(int fd)
#endif #endif
} }
void init_async_pipe(int file_des[2])
{
if (pipe(file_des) < 0)
g_error("Couldn't open pipe: %s", strerror(errno));
if (set_nonblocking(file_des[0]) < 0)
g_error("Couldn't set non-blocking I/O: %s", strerror(errno));
if (set_nonblocking(file_des[1]) < 0)
g_error("Couldn't set non-blocking I/O: %s", strerror(errno));
}
int stringFoundInStringArray(const char *const*array, const char *suffix) int stringFoundInStringArray(const char *const*array, const char *suffix)
{ {
while (array && *array) { while (array && *array) {
......
...@@ -95,8 +95,6 @@ char *parsePath(char *path); ...@@ -95,8 +95,6 @@ char *parsePath(char *path);
int set_nonblocking(int fd); int set_nonblocking(int fd);
void init_async_pipe(int file_des[2]);
int stringFoundInStringArray(const char *const*array, const char *suffix); int stringFoundInStringArray(const char *const*array, const char *suffix);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment