On 02/20/2012 04:30 PM, Michael S. Tsirkin wrote:
On Wed, Dec 14, 2011 at 08:43:20AM -0500, Stefan Berger wrote:
+
+static void *tpm_passthrough_thread(void *d)
+{
+    TPMPassthruThreadParams *thr_parms = d;
+    TPMPassthruState *tpm_pt = thr_parms->tb->s.tpm_pt;
+    uint32_t in_len;
+
+    dprintf("tpm_passthrough: THREAD IS STARTING\n");
+
+    /* start command processing */
+    while (!tpm_pt->thread_terminate) {
IMO you want to checvk thread_terminate undet a lock/


The way the termination flag is used along with the condition it isn't necessary to call it with a lock held. It may run into the condition but then be woken up with a signal and then again check the flag and terminate.

+        /* receive and handle commands */
+        in_len = 0;
+        do {
+            dprintf("tpm_passthrough: waiting for commands...\n");
+
+            if (tpm_pt->thread_terminate) {
+                break;
+            }
+
This will have to be duplicate in each backend, no?

There is this sequence of code around the condition that helps us waiting for the front-end to send a command that is indeed repeated in every backend. I isolated that now but would like to keep the general thread more flexible and inside the individual backends. There is quite some code that is different in every backend.


So I would say make this logic part of backend
and expose some api.

Ok, a single function for now:

void tpm_backend_wait_for_command(TPMState *tpm_state);


You can then call it from backend or invoke
backend callbacks from frontend.


 I was only going to invoke it from within the backend thread.


   Stefan


Reply via email to