This patch fixed what I believe to be a few problems with the saAmf
service's dispatch code. The few things I changed in this patch seem
to be fallout from the ipc changes that went in a while back.

First, we only need to hold a lock on the dispatch_mutex while calling
coroipcc_dispatch_recv. This removes the need to call
pthread_mutex_unlock in a few other places, and allows us to remove
error_unlock.

Also put finalize == 1 check under dispatch_avail == -1.

Index: lib/amf.c
===================================================================
--- lib/amf.c   (revision 1787)
+++ lib/amf.c   (working copy)
@@ -202,38 +202,39 @@
        error = saHandleInstanceGet (&amfHandleDatabase, amfHandle,
                (void *)&amfInstance);
        if (error != SA_AIS_OK) {
-               return (error);
+               goto error_exit;
        }
 
        /*
-        * Timeout instantly for SA_DISPATCH_ALL
+        * Timeout instantly for SA_DISPATCH_ALL, otherwise don't timeout
+        * for SA_DISPATCH_BLOCKING or SA_DISPATCH_ONE
         */
        if (dispatchFlags == SA_DISPATCH_ALL) {
                timeout = 0;
        }
 
        do {
+               pthread_mutex_lock (&amfInstance->dispatch_mutex);
+
                dispatch_avail = coroipcc_dispatch_recv (amfInstance->ipc_ctx,
                        (void *)&dispatch_data, sizeof (dispatch_data), 
timeout);
 
-               pthread_mutex_lock (&amfInstance->dispatch_mutex);
+               pthread_mutex_unlock (&amfInstance->dispatch_mutex);
 
-               /*
-                * Handle has been finalized in another thread
-                */
-               if (amfInstance->finalize == 1) {
-                       error = SA_AIS_OK;
-                       goto error_unlock;
-               }
-
                if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
-                       pthread_mutex_unlock (&amfInstance->dispatch_mutex);
                        break; /* exit do while cont is 1 loop */
                } else
                if (dispatch_avail == 0) {
-                       pthread_mutex_unlock (&amfInstance->dispatch_mutex);
-                       continue; /* next poll */
+                       continue;
                }
+               if (dispatch_avail == -1) {
+                       if (amfInstance->finalize == 1) {
+                               error = SA_AIS_OK;
+                       } else {
+                               error = SA_AIS_ERR_LIBRARY;
+                       }
+                       goto error_put;
+               }
 
                /*
                 * Make copy of callbacks, message data, unlock instance, and 
call callback
@@ -242,7 +243,6 @@
                 */
 
                memcpy (&callbacks, &amfInstance->callbacks, sizeof 
(SaAmfCallbacksT));
-               pthread_mutex_unlock (&amfInstance->dispatch_mutex);
 
                /*
                 * Dispatch incoming response
@@ -355,11 +355,9 @@
                }
        } while (cont);
 
-error_unlock:
-       pthread_mutex_unlock (&amfInstance->dispatch_mutex);
 error_put:
        saHandleInstancePut (&amfHandleDatabase, amfHandle);
-
+error_exit:
        return (error);
 }
 
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to