mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-11-05 20:35:44 +00:00
qemu-thread: implement joinable threads for POSIX
Allow to control if a QEMU thread is created joinable or not. Make it not joinable by default to avoid that we keep the associated resources around when terminating a thread without joining it (what we couldn't do so far for obvious reasons). The audio subsystem will need the join feature when converting it to QEMU threading/locking abstractions, so provide that service. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
cf21871479
commit
8763046b4b
1 changed files with 26 additions and 2 deletions
|
@ -121,17 +121,29 @@ void qemu_thread_create(QemuThread *thread,
|
|||
{
|
||||
sigset_t set, oldset;
|
||||
int err;
|
||||
pthread_attr_t attr;
|
||||
|
||||
assert(mode == QEMU_THREAD_DETACHED);
|
||||
err = pthread_attr_init(&attr);
|
||||
if (err) {
|
||||
error_exit(err, __func__);
|
||||
}
|
||||
if (mode == QEMU_THREAD_DETACHED) {
|
||||
err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
if (err) {
|
||||
error_exit(err, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
/* Leave signal handling to the iothread. */
|
||||
sigfillset(&set);
|
||||
pthread_sigmask(SIG_SETMASK, &set, &oldset);
|
||||
err = pthread_create(&thread->thread, NULL, start_routine, arg);
|
||||
err = pthread_create(&thread->thread, &attr, start_routine, arg);
|
||||
if (err)
|
||||
error_exit(err, __func__);
|
||||
|
||||
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
|
||||
void qemu_thread_get_self(QemuThread *thread)
|
||||
|
@ -148,3 +160,15 @@ void qemu_thread_exit(void *retval)
|
|||
{
|
||||
pthread_exit(retval);
|
||||
}
|
||||
|
||||
void *qemu_thread_join(QemuThread *thread)
|
||||
{
|
||||
int err;
|
||||
void *ret;
|
||||
|
||||
err = pthread_join(thread->thread, &ret);
|
||||
if (err) {
|
||||
error_exit(err, __func__);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue