[Cbe-oss-dev] [PATCH 2/10] MARS: task event flag fix bit clearing

Kazunori Asayama asayama at sm.sony.co.jp
Thu Aug 28 17:16:51 EST 2008


Yuji Mano wrote:
> This fixes a bug in host-side task event flag where the wait routine was
> clearing the bits even when the clear mode is not set to auto.
> 
> This also fixes a bug in mpu-side task event flag where the wait routine was not
> clearing the bits if the event bit was already set at the initial time of call
> without needing to enter the wait state.
> 
> Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
> 
> ---
>  src/host/lib/mars_task_event_flag.c |   56 ++++++++++++++++--------------------
>  src/mpu/lib/mars_task_event_flag.c  |    4 ++
>  2 files changed, 30 insertions(+), 30 deletions(-)
> 
> --- a/src/host/lib/mars_task_event_flag.c
> +++ b/src/host/lib/mars_task_event_flag.c
> @@ -171,43 +171,39 @@ int mars_task_event_flag_wait(struct mar
>  	MARS_CHECK_RET(((uintptr_t)event_flag & MARS_TASK_EVENT_FLAG_ALIGN_MASK)
>  			== 0, MARS_ERROR_ALIGN);
>  
> -	do {
> -		/* check condition based on wait mode */
> -		switch (mask_mode) {
> -		case MARS_TASK_EVENT_FLAG_MASK_OR:
> +	int bits;

The variable 'bits' isn't used.

> +
> +	mars_mutex_lock((struct mars_mutex *)event_flag);
> +
> +	/* check condition based on wait mode */
> +	switch (mask_mode) {
> +	case MARS_TASK_EVENT_FLAG_MASK_OR:
> +		while ((event_flag->bits | mask) == 0) {
> +			bits = event_flag->bits;
> +			mars_mutex_unlock((struct mars_mutex *)event_flag);
>  			while ((event_flag->bits | mask) == 0)
> -				sched_yield();
> -			break;
> -		case MARS_TASK_EVENT_FLAG_MASK_AND:
> +-				sched_yield();

An extra '-' is added at the beginning of this line. That will be parsed
as an unary operator '-' by the compiler.

> +			mars_mutex_lock((struct mars_mutex *)event_flag);
> +		}
> +		break;
> +	case MARS_TASK_EVENT_FLAG_MASK_AND:
> +		while ((event_flag->bits & mask) != mask) {
> +			bits = event_flag->bits;
> +			mars_mutex_unlock((struct mars_mutex *)event_flag);
>  			while ((event_flag->bits & mask) != mask)
>  				sched_yield();
> -			break;
> +			mars_mutex_lock((struct mars_mutex *)event_flag);
>  		}
> +		break;
> +	}
>  
> -		mars_mutex_lock((struct mars_mutex *)event_flag);
> +	/* clear event if clear mode is auto */
> +	if (event_flag->clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_AUTO)
> +		event_flag->bits &= ~mask;
>  
> -		/* check condition again after locking mutex */
> -		switch (mask_mode) {
> -		case MARS_TASK_EVENT_FLAG_MASK_OR:
> -			if ((event_flag->bits | mask) != 0) {
> -				event_flag->bits &= ~mask;
> -				mars_mutex_unlock(
> -					(struct mars_mutex *)event_flag);
> -				return MARS_SUCCESS;
> -			}
> -			break;
> -		case MARS_TASK_EVENT_FLAG_MASK_AND:
> -			if ((event_flag->bits & mask) == mask) {
> -				event_flag->bits &= ~mask;
> -				mars_mutex_unlock(
> -					(struct mars_mutex *)event_flag);
> -				return MARS_SUCCESS;
> -			}
> -			break;
> -		}
> +	mars_mutex_unlock((struct mars_mutex *)event_flag);
>  
> -		mars_mutex_unlock((struct mars_mutex *)event_flag);
> -	} while (1);
> +	return MARS_SUCCESS;
>  }
>  
>  int mars_task_event_flag_try_wait(struct mars_task_event_flag *event_flag,
> --- a/src/mpu/lib/mars_task_event_flag.c
> +++ b/src/mpu/lib/mars_task_event_flag.c
> @@ -226,6 +226,10 @@ int mars_task_event_flag_wait(uint64_t e
>  		return MARS_SUCCESS;
>  	}
>  
> +	/* clear event if clear mode is auto */
> +	if (event_flag.clear_mode == MARS_TASK_EVENT_FLAG_CLEAR_AUTO)
> +		event_flag.bits &= ~mask;
> +
>  	mars_mutex_unlock_put(event_flag_ea, (struct mars_mutex *)&event_flag);
>  
>  	return MARS_SUCCESS;
> 
> 
> 

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list