qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: jan.kiszka@siemens.com, alevy@redhat.com
Subject: [Qemu-devel] [PATCH 2/4] qemu-thread: implement joinable threads for POSIX
Date: Tue,  6 Dec 2011 18:05:53 +0100	[thread overview]
Message-ID: <1323191155-22549-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1323191155-22549-1-git-send-email-pbonzini@redhat.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

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>
---
 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;
+}
-- 
1.7.7.1

  parent reply	other threads:[~2011-12-06 17:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-06 17:05 [Qemu-devel] [PATCH 0/4] add qemu_thread_join, use it to fix bug in ccid Paolo Bonzini
2011-12-06 17:05 ` [Qemu-devel] [PATCH 1/4] qemu-thread: add API for joinable threads Paolo Bonzini
2011-12-06 17:40   ` Jan Kiszka
2011-12-06 17:05 ` Paolo Bonzini [this message]
2011-12-06 17:37   ` [Qemu-devel] [PATCH 2/4] qemu-thread: implement joinable threads for POSIX Jan Kiszka
2011-12-06 17:05 ` [Qemu-devel] [PATCH 3/4] qemu-thread: implement joinable threads for Win32 Paolo Bonzini
2011-12-06 17:39   ` Jan Kiszka
2011-12-06 18:10     ` Paolo Bonzini
2011-12-06 17:05 ` [Qemu-devel] [PATCH 4/4] ccid: make threads joinable Paolo Bonzini
2011-12-07 11:35   ` Alon Levy
2011-12-06 17:37 ` [Qemu-devel] [PATCH 0/4] add qemu_thread_join, use it to fix bug in ccid Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1323191155-22549-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alevy@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).