From patchwork Tue Dec 6 17:05:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 129748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 28CAA1007D5 for ; Wed, 7 Dec 2011 04:06:55 +1100 (EST) Received: from localhost ([::1]:43977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyTk-0000yR-KS for incoming@patchwork.ozlabs.org; Tue, 06 Dec 2011 12:06:52 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyTB-0007fr-Dg for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXyT5-00069L-MZ for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:17 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:42926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXyT5-00068U-Gf for qemu-devel@nongnu.org; Tue, 06 Dec 2011 12:06:11 -0500 Received: by mail-iy0-f173.google.com with SMTP id j26so323826iaf.4 for ; Tue, 06 Dec 2011 09:06:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=1jd4aN67I/9QJY3eQ+5y1842uB3ND6hDi0PqBVM0lOk=; b=wm1yeR7iuOie29hi2YXlaozyJdPo6A4/BWNh2EzTw16oIQkZ7iO88jfSBK5Sfim0XM Z5UcQKc8lWo+xfd2gOZTQ3eI9seiqP+hE4lUwKsGVCYAu2QRbLwY1j4+snOqAcR9Ip8T lC2B0CqvHFEt2sHu4shontNXtjtR8iPg2mCYY= Received: by 10.231.64.210 with SMTP id f18mr3443886ibi.80.1323191171350; Tue, 06 Dec 2011 09:06:11 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id ew6sm50623315igc.4.2011.12.06.09.06.08 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Dec 2011 09:06:09 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 6 Dec 2011 18:05:53 +0100 Message-Id: <1323191155-22549-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1323191155-22549-1-git-send-email-pbonzini@redhat.com> References: <1323191155-22549-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: jan.kiszka@siemens.com, alevy@redhat.com Subject: [Qemu-devel] [PATCH 2/4] qemu-thread: implement joinable threads for POSIX X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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,16 +122,28 @@ void qemu_thread_create(QemuThread *thread, sigset_t set, oldset; int err; - assert(mode == QEMU_THREAD_DETACHED); + pthread_attr_t attr; + 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; +}