tpm-be: call request_completed() out of thread

Lift from the backend implementation the responsability to call the
request_completed() callback outside of thread context. This also
simplify frontend/interface work, as they no longer need to care
whether the callback is called from a different thread.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Marc-André Lureau 2017-11-06 19:39:02 +01:00 committed by Stefan Berger
parent 36e8658924
commit 689990598a
6 changed files with 27 additions and 29 deletions

View file

@ -18,14 +18,25 @@
#include "qapi/qmp/qerror.h"
#include "sysemu/tpm.h"
#include "qemu/thread.h"
#include "qemu/main-loop.h"
static void tpm_backend_request_completed_bh(void *opaque)
{
TPMBackend *s = TPM_BACKEND(opaque);
TPMIfClass *tic = TPM_IF_GET_CLASS(s->tpmif);
tic->request_completed(s->tpmif);
}
static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
{
TPMBackend *s = TPM_BACKEND(user_data);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
assert(k->handle_request != NULL);
k->handle_request(s, (TPMBackendCmd *)data);
qemu_bh_schedule(s->bh);
}
static void tpm_backend_thread_end(TPMBackend *s)
@ -193,6 +204,7 @@ static void tpm_backend_instance_init(Object *obj)
tpm_backend_prop_set_opened,
NULL);
s->fe_model = -1;
s->bh = qemu_bh_new(tpm_backend_request_completed_bh, s);
}
static void tpm_backend_instance_finalize(Object *obj)
@ -202,6 +214,7 @@ static void tpm_backend_instance_finalize(Object *obj)
object_unref(OBJECT(s->tpmif));
g_free(s->id);
tpm_backend_thread_end(s);
qemu_bh_delete(s->bh);
}
static const TypeInfo tpm_backend_info = {