Also, this patch changes how/when timeout is set to 0. Existing code
would set timeout=0 when dispatchFlags was set to SA_DISPATCH_ALL -or-
SA_DISPATCH_ONE. This is not correct. We should only set timeout=0
when dispatchFlags == SA_DISPATCH_ALL.

This is worth nothing, and I failed to mention it in my original
email.

Ryan


On Thu, Apr 09, 2009 at 03:47:03PM -0500, Ryan O'Hara wrote:
> 
> This patch fixes a few issues with the event service dispatch code. It
> is similar to the patch I posted eariler for the saAmf service.
> 
> Fixes include:
> 
> * Change checking of dispatchFlags to be same as other services.
> * Wrap coroipcc_dispatch_recv with pthread_mutex_lock/unlock. As a
>   result, remove other unlocks. Note that it appears that existing
>   code never called lock on dispatch_mutex.
> * Change finalize check to only occur when dispatch_avail == -1.
> * Remove ignore_dispatch variable, which wasn't used.
> 

> Index: lib/evt.c
> ===================================================================
> --- lib/evt.c (revision 1787)
> +++ lib/evt.c (working copy)
> @@ -597,48 +597,53 @@
>       struct event_instance *evti;
>       SaEvtEventHandleT event_handle;
>       SaEvtCallbacksT callbacks;
> -     int ignore_dispatch = 0;
>       int cont = 1; /* always continue do loop except when set to 0 */
>       struct lib_event_data *evt = 0;
>  
> -     if (dispatchFlags < SA_DISPATCH_ONE || 
> -                     dispatchFlags > SA_DISPATCH_BLOCKING) {
> +     if (dispatchFlags != SA_DISPATCH_ONE &&
> +         dispatchFlags != SA_DISPATCH_ALL &&
> +         dispatchFlags != SA_DISPATCH_BLOCKING) {
> +
>               return SA_AIS_ERR_INVALID_PARAM;
>       }
>  
>       error = saHandleInstanceGet(&evt_instance_handle_db, evtHandle,
>               (void *)&evti);
>       if (error != SA_AIS_OK) {
> -             return error;
> +             goto dispatch_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 || dispatchFlags == 
> SA_DISPATCH_ONE) {
> +     if (dispatchFlags == SA_DISPATCH_ALL) {
>               timeout = 0;
>       }
>  
>       do {
> +             pthread_mutex_lock (&evti->ei_dispatch_mutex);
> +
>               dispatch_avail = coroipcc_dispatch_recv (evti->ipc_ctx,
>                       (void *)&evti->ei_dispatch_data, sizeof 
> (evti->ei_dispatch_data), timeout);
>  
> -             /*
> -              * Handle has been finalized in another thread
> -              */
> -             if (evti->ei_finalize == 1) {
> -                     error = SA_AIS_OK;
> -                     goto dispatch_unlock;
> -             }
> +             pthread_mutex_unlock (&evti->ei_dispatch_mutex);
>  
>               if (dispatch_avail == 0 && dispatchFlags == SA_DISPATCH_ALL) {
> -                     pthread_mutex_unlock (&evti->ei_dispatch_mutex);
>                       break; /* exit do while cont is 1 loop */
>               } else
>               if (dispatch_avail == 0) {
> -                     pthread_mutex_unlock (&evti->ei_dispatch_mutex);
> -                     continue; /* next poll */
> +                     continue;
>               }
> +             if (dispatch_avail == -1) {
> +                     if (evti->ei_finalize == 1) {
> +                             error = SA_AIS_OK;
> +                     } else {
> +                             error = SA_AIS_ERR_LIBRARY;
> +                     }
> +                     goto dispatch_put;
> +             }
> +             
>  
>               /*
>                * Make copy of callbacks, message data, unlock instance, 
> @@ -732,26 +737,16 @@
>               default:
>                       printf ("Dispatch: Bad message type 0x%x\n", 
> evti->ei_dispatch_data.header.id);
>                       error = SA_AIS_ERR_LIBRARY;     
> -                     goto dispatch_unlock;
>               }
>  
> -             pthread_mutex_unlock(&evti->ei_dispatch_mutex);
> -
>               /*
>                * Determine if more messages should be processed
>                */
>               switch (dispatchFlags) {
>               case SA_DISPATCH_ONE:
> -                     if (ignore_dispatch) {
> -                             ignore_dispatch = 0;
> -                     } else {
> -                             cont = 0;
> -                     }
> +                     cont = 0;
>                       break;
>               case SA_DISPATCH_ALL:
> -                     if (ignore_dispatch) {
> -                             ignore_dispatch = 0;
> -                     }
>                       break;
>               case SA_DISPATCH_BLOCKING:
>                       break;
> @@ -760,10 +755,9 @@
>  
>       goto dispatch_put;
>  
> -dispatch_unlock:
> -     pthread_mutex_unlock(&evti->ei_dispatch_mutex);
>  dispatch_put:
>       saHandleInstancePut(&evt_instance_handle_db, evtHandle);
> +dispatch_exit:
>       return error;
>  }
>  

> _______________________________________________
> Openais mailing list
> [email protected]
> https://lists.linux-foundation.org/mailman/listinfo/openais
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to