source: rtems/cpukit/posix/src/pthreadsetschedprio.c @ 2dd098a

5
Last change on this file since 2dd098a was 2dd098a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/16 at 07:33:11

score: Introduce Thread_Scheduler_control::home

Replace Thread_Scheduler_control::control and
Thread_Scheduler_control::own_control with new
Thread_Scheduler_control::home.

Update #2556.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#if HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include <pthread.h>
14#include <errno.h>
15
16#include <rtems/posix/priorityimpl.h>
17#include <rtems/posix/threadsup.h>
18#include <rtems/score/threadimpl.h>
19#include <rtems/score/schedulerimpl.h>
20
21int pthread_setschedprio( pthread_t thread, int prio )
22{
23  Thread_Control          *the_thread;
24  Per_CPU_Control         *cpu_self;
25  Thread_queue_Context     queue_context;
26  const Scheduler_Control *scheduler;
27  Priority_Control         new_priority;
28  bool                     valid;
29
30  the_thread = _Thread_Get( thread, &queue_context.Lock_context.Lock_context );
31
32  if ( the_thread == NULL ) {
33    return ESRCH;
34  }
35
36  _Thread_queue_Context_clear_priority_updates( &queue_context );
37  _Thread_Wait_acquire_critical( the_thread, &queue_context );
38
39  scheduler = _Thread_Scheduler_get_home( the_thread );
40
41  new_priority = _POSIX_Priority_To_core( scheduler, prio, &valid );
42  if ( !valid ) {
43    _Thread_Wait_release( the_thread, &queue_context );
44    return EINVAL;
45  }
46
47  _Thread_Priority_change(
48    the_thread,
49    &the_thread->Real_priority,
50    new_priority,
51    true,
52    &queue_context
53  );
54
55  cpu_self = _Thread_Dispatch_disable_critical(
56    &queue_context.Lock_context.Lock_context
57  );
58  _Thread_Wait_release( the_thread, &queue_context );
59
60  _Thread_Priority_update( &queue_context );
61
62  _Thread_Dispatch_enable( cpu_self );
63  return 0;
64}
Note: See TracBrowser for help on using the repository browser.