From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ra8db-0007qV-KX for qemu-devel@nongnu.org; Mon, 12 Dec 2011 11:22:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ra8dX-00053p-K1 for qemu-devel@nongnu.org; Mon, 12 Dec 2011 11:21:59 -0500 Received: from mail-qy0-f173.google.com ([209.85.216.173]:65267) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ra8dX-00053l-DE for qemu-devel@nongnu.org; Mon, 12 Dec 2011 11:21:55 -0500 Received: by qcsd15 with SMTP id d15so4367501qcs.4 for ; Mon, 12 Dec 2011 08:21:54 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 12 Dec 2011 17:21:32 +0100 Message-Id: <1323706894-29959-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1323706894-29959-1-git-send-email-pbonzini@redhat.com> References: <1323706894-29959-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/4] qemu-thread: implement joinable threads for POSIX List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: jan.kiszka@siemens.com, alevy@redhat.com From: Jan Kiszka 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 Signed-off-by: Paolo Bonzini --- qemu-thread-posix.c | 28 ++++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c index 49d3388..603ff3d 100644 --- a/qemu-thread-posix.c +++ b/qemu-thread-posix.c @@ -122,17 +122,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 +162,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; +} -- 1.7.7.1