* Protected by sigio_lock(), also used by sigio_cleanup, which is an
* exitcall.
*/
-static int write_sigio_pid = -1;
-static unsigned long write_sigio_stack;
+static struct os_helper_thread *write_sigio_td;
/*
* These arrays are initialized before the sigio thread is started, and
static struct pollfds next_poll;
static struct pollfds all_sigio_fds;
-static int write_sigio_thread(void *unused)
+static void *write_sigio_thread(void *unused)
{
struct pollfds *fds, tmp;
struct pollfd *p;
int i, n, respond_fd;
char c;
- os_set_pdeathsig();
- os_fix_helper_signals();
+ os_fix_helper_thread_signals();
+
fds = ¤t_poll;
while (1) {
n = poll(fds->poll, fds->used, -1);
}
}
- return 0;
+ return NULL;
}
static int need_poll(struct pollfds *polls, int n)
return;
fail:
/* Critical section start */
- if (write_sigio_pid != -1) {
- os_kill_process(write_sigio_pid, 1);
- free_stack(write_sigio_stack, 0);
+ if (write_sigio_td) {
+ os_kill_helper_thread(write_sigio_td);
+ write_sigio_td = NULL;
}
- write_sigio_pid = -1;
close(sigio_private[0]);
close(sigio_private[1]);
close(write_sigio_fds[0]);
* sigio_cleanup has already run, then update_thread will hang
* or fail because the thread is no longer running.
*/
- if (write_sigio_pid == -1)
+ if (!write_sigio_td)
return -EIO;
for (i = 0; i < current_poll.used; i++) {
int err;
int l_write_sigio_fds[2];
int l_sigio_private[2];
- int l_write_sigio_pid;
+ struct os_helper_thread *l_write_sigio_td;
/* We call this *tons* of times - and most ones we must just fail. */
sigio_lock();
- l_write_sigio_pid = write_sigio_pid;
+ l_write_sigio_td = write_sigio_td;
sigio_unlock();
- if (l_write_sigio_pid != -1)
+ if (l_write_sigio_td)
return;
err = os_pipe(l_write_sigio_fds, 1, 1);
* Did we race? Don't try to optimize this, please, it's not so likely
* to happen, and no more than once at the boot.
*/
- if (write_sigio_pid != -1)
+ if (write_sigio_td)
goto out_free;
current_poll = ((struct pollfds) { .poll = p,
memcpy(write_sigio_fds, l_write_sigio_fds, sizeof(l_write_sigio_fds));
memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
- write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
- CLONE_FILES | CLONE_VM,
- &write_sigio_stack);
-
- if (write_sigio_pid < 0)
+ err = os_run_helper_thread(&write_sigio_td, write_sigio_thread, NULL);
+ if (err < 0)
goto out_clear;
sigio_unlock();
return;
out_clear:
- write_sigio_pid = -1;
+ write_sigio_td = NULL;
write_sigio_fds[0] = -1;
write_sigio_fds[1] = -1;
sigio_private[0] = -1;
static void sigio_cleanup(void)
{
- if (write_sigio_pid == -1)
+ if (!write_sigio_td)
return;
- os_kill_process(write_sigio_pid, 1);
- free_stack(write_sigio_stack, 0);
- write_sigio_pid = -1;
+ os_kill_helper_thread(write_sigio_td);
+ write_sigio_td = NULL;
}
__uml_exitcall(sigio_cleanup);