???????????????????????????????????????????????????????????????????檔????????????chg_pri_mutex???????????????change_interal_task_priority??????ж???????????????????????ж???ζ????????????????????????????????????????????????????

RAW_U8 chg_pri_mutex(RAW_TASK_OBJ *tcb?? RAW_U8 priority?? RAW_U16 *error)
{
 RAW_MUTEX *mtxcb;
 RAW_U8 hi_pri?? low_pri?? pri;
 RAW_TASK_OBJ *first_block_task;
 LIST *block_list_head;
 
 hi_pri  = priority;
 low_pri = 0;
 
 mtxcb = (RAW_MUTEX *)(tcb->block_obj);
 
 if (mtxcb) {

  /*if it is blocked on mutex*/
  if (mtxcb->common_block_obj.object_type == RAW_MUTEX_OBJ_TYPE) {
  
   if (mtxcb->policy == RAW_MUTEX_CEILING_POLICY) {
    pri = mtxcb->ceiling_prio;
   
    if (pri > low_pri) {
     low_pri = pri;
    }
   }
  }
 }

 /* Locked Mutex */
 pri = hi_pri;
 for (mtxcb = tcb->mtxlist; mtxcb != 0; mtxcb = mtxcb->mtxlist) {
  switch (mtxcb->policy) {
  
    case RAW_MUTEX_CEILING_POLICY:
   pri = mtxcb->ceiling_prio;
   if ( pri > low_pri ) {
    low_pri = pri;
   }
   break;
  
    case RAW_MUTEX_INHERIT_POLICY:
    
   block_list_head = &mtxcb->common_block_obj.block_list;
  
   if (!is_list_empty(block_list_head)) {
    first_block_task = list_entry(block_list_head->next?? RAW_TASK_OBJ?? task_list);
    pri = first_block_task->priority;
   }
  
   break;
  
    default:
   /* nothing to do */
   break;
  }
  if ( pri < hi_pri ) {
   hi_pri = pri;
  }
 }

 if (priority < low_pri) {
 
  *error = RAW_EXCEED_CEILING_PRIORITY;
  return RAW_EXCEED_CEILING_PRIORITY;
 }

 *error = RAW_SUCCESS;
 return hi_pri;
}