Пример #1
0
static rtems_status_code _RTEMS_tasks_Set_priority(
  Thread_Control          *the_thread,
  const Scheduler_Control *scheduler,
  Priority_Control         new_priority,
  Thread_queue_Context    *queue_context
)
{
  Priority_Control core_new_priority;
  bool             valid;
  Per_CPU_Control *cpu_self;

  core_new_priority = _RTEMS_Priority_To_core(
    scheduler,
    new_priority,
    &valid
  );

  if ( !valid ) {
    _Thread_Wait_release( the_thread, queue_context );
    return RTEMS_INVALID_PRIORITY;
  }

  _Thread_Priority_change(
    the_thread,
    &the_thread->Real_priority,
    core_new_priority,
    false,
    queue_context
  );
  cpu_self = _Thread_queue_Dispatch_disable( queue_context );
  _Thread_Wait_release( the_thread, queue_context );
  _Thread_Priority_update( queue_context );
  _Thread_Dispatch_enable( cpu_self );
  return RTEMS_SUCCESSFUL;
}
Пример #2
0
rtems_status_code rtems_task_set_scheduler(
  rtems_id            task_id,
  rtems_id            scheduler_id,
  rtems_task_priority priority
)
{
  const Scheduler_Control *scheduler;
  Thread_Control          *the_thread;
  Thread_queue_Context     queue_context;
  ISR_lock_Context         state_context;
  Per_CPU_Control         *cpu_self;
  bool                     valid;
  Priority_Control         core_priority;
  Status_Control           status;

  if ( !_Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
    return RTEMS_INVALID_ID;
  }

  core_priority = _RTEMS_Priority_To_core( scheduler, priority, &valid );
  if ( !valid ) {
    return RTEMS_INVALID_PRIORITY;
  }

  _Thread_queue_Context_initialize( &queue_context );
  the_thread = _Thread_Get( task_id, &queue_context.Lock_context.Lock_context );

  if ( the_thread == NULL ) {
#if defined(RTEMS_MULTIPROCESSING)
    if ( _Thread_MP_Is_remote( task_id ) ) {
      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    }
#endif

    return RTEMS_INVALID_ID;
  }

  cpu_self = _Thread_Dispatch_disable_critical(
    &queue_context.Lock_context.Lock_context
  );

  _Thread_Wait_acquire_critical( the_thread, &queue_context );
  _Thread_State_acquire_critical( the_thread, &state_context );

  status = _Scheduler_Set( scheduler, the_thread, core_priority );

  _Thread_State_release_critical( the_thread, &state_context );
  _Thread_Wait_release( the_thread, &queue_context );
  _Thread_Dispatch_enable( cpu_self );
  return _Status_Get( status );
}
static bool _RTEMS_tasks_Set_priority_filter(
  Thread_Control   *the_thread,
  Priority_Control *new_priority_p,
  void             *arg
)
{
  RTEMS_tasks_Set_priority_context *context;
  const Scheduler_Control          *scheduler;
  bool                              valid;
  Priority_Control                  current_priority;
  Priority_Control                  new_priority;

  context = arg;
  scheduler = _Scheduler_Get_own( the_thread );
  current_priority = _Thread_Get_priority( the_thread );

  context->scheduler = scheduler;
  context->old_priority = current_priority;

  new_priority = _RTEMS_Priority_To_core(
    scheduler,
    context->new_priority,
    &valid
  );

  *new_priority_p = new_priority;

  if ( !valid ) {
    context->status = RTEMS_INVALID_PRIORITY;
    return false;
  }

  the_thread->real_priority = new_priority;
  context->status = STATUS_SUCCESSFUL;

  return _Thread_Priority_less_than( current_priority, new_priority )
    || !_Thread_Owns_resources( the_thread );
}
Пример #4
0
static rtems_status_code _Semaphore_Set_priority(
    Semaphore_Control       *the_semaphore,
    const Scheduler_Control *scheduler,
    rtems_task_priority      new_priority,
    rtems_task_priority     *old_priority_p,
    Thread_queue_Context    *queue_context
)
{
    rtems_status_code    sc;
    bool                 valid;
    Priority_Control     core_priority;
    Priority_Control     old_priority;

    core_priority = _RTEMS_Priority_To_core( scheduler, new_priority, &valid );
    if ( new_priority != RTEMS_CURRENT_PRIORITY && !valid ) {
        return RTEMS_INVALID_PRIORITY;
    }

    _Thread_queue_Acquire_critical(
        &the_semaphore->Core_control.Wait_queue,
        &queue_context->Lock_context
    );

    switch ( the_semaphore->variant ) {
    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
        sc = _Semaphore_Is_scheduler_valid(
                 &the_semaphore->Core_control.Mutex,
                 scheduler
             );

        old_priority = _CORE_ceiling_mutex_Get_priority(
                           &the_semaphore->Core_control.Mutex
                       );

        if ( sc == RTEMS_SUCCESSFUL && new_priority != RTEMS_CURRENT_PRIORITY ) {
            _CORE_ceiling_mutex_Set_priority(
                &the_semaphore->Core_control.Mutex,
                core_priority
            );
        }

        break;
#if defined(RTEMS_SMP)
    case SEMAPHORE_VARIANT_MRSP:
        old_priority = _MRSP_Get_priority(
                           &the_semaphore->Core_control.MRSP,
                           scheduler
                       );

        if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
            _MRSP_Set_priority(
                &the_semaphore->Core_control.MRSP,
                scheduler,
                core_priority
            );
        }

        sc = RTEMS_SUCCESSFUL;
        break;
#endif
    default:
        _Assert(
            the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
            || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
            || the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
            || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
        );
        old_priority = 0;
        sc = RTEMS_NOT_DEFINED;
        break;
    }

    _Thread_queue_Release(
        &the_semaphore->Core_control.Wait_queue,
        &queue_context->Lock_context
    );

    *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
    return sc;
}