diff options
author | malc <av1474@comtv.ru> | 2009-09-25 00:20:44 +0400 |
---|---|---|
committer | malc <av1474@comtv.ru> | 2009-09-27 04:16:02 +0400 |
commit | ee3993069ff55fa6f1c64daf1e09963e340db8e4 (patch) | |
tree | c4241460a7a95c93c223443c856807c0edb2f0ce /posix-aio-compat.c | |
parent | bedda79c1eecb62316dc7698a886262fd496864e (diff) | |
download | qemu-ee3993069ff55fa6f1c64daf1e09963e340db8e4.zip qemu-ee3993069ff55fa6f1c64daf1e09963e340db8e4.tar.gz qemu-ee3993069ff55fa6f1c64daf1e09963e340db8e4.tar.bz2 |
posix-aio-compat: avoid signal race when spawning a thread
Signed-off-by: malc <av1474@comtv.ru>
Diffstat (limited to 'posix-aio-compat.c')
-rw-r--r-- | posix-aio-compat.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 68cbec8..400d898 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -301,14 +301,9 @@ static size_t handle_aiocb_rw(struct qemu_paiocb *aiocb) static void *aio_thread(void *unused) { pid_t pid; - sigset_t set; pid = getpid(); - /* block all signals */ - if (sigfillset(&set)) die("sigfillset"); - if (sigprocmask(SIG_BLOCK, &set, NULL)) die("sigprocmask"); - while (1) { struct qemu_paiocb *aiocb; size_t ret = 0; @@ -369,9 +364,18 @@ static void *aio_thread(void *unused) static void spawn_thread(void) { + sigset_t set, oldset; + cur_threads++; idle_threads++; + + /* block all signals */ + if (sigfillset(&set)) die("sigfillset"); + if (sigprocmask(SIG_SETMASK, &set, &oldset)) die("sigprocmask"); + thread_create(&thread_id, &attr, aio_thread, NULL); + + if (sigprocmask(SIG_SETMASK, &oldset, NULL)) die("sigprocmask restore"); } static void qemu_paio_submit(struct qemu_paiocb *aiocb) |