source: rtems/cpukit/posix/src/pthreadsetschedparam.c @ be1b8a7

4.115
Last change on this file since be1b8a7 was 4b48ece0, checked in by Sebastian Huber <sebastian.huber@…>, on 07/22/13 at 08:21:03

score: Create watchdog implementation header

Move implementation specific parts of watchdog.h and watchdog.inl into
new header file watchdogimpl.h. The watchdog.h contains now only the
application visible API.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Function sets scheduling policy and parameters of the thread
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  13.5.2 Dynamic Thread Scheduling Parameters Access,
10 *         P1003.1c/Draft 10, p. 124
11 */
12
13/*  COPYRIGHT (c) 1989-2007.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.com/license/LICENSE.
19 */
20
21#if HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <pthread.h>
26#include <errno.h>
27
28#include <rtems/system.h>
29#include <rtems/score/watchdogimpl.h>
30#include <rtems/posix/pthreadimpl.h>
31#include <rtems/posix/priorityimpl.h>
32#include <rtems/posix/time.h>
33
34int pthread_setschedparam(
35  pthread_t           thread,
36  int                 policy,
37  struct sched_param *param
38)
39{
40  register Thread_Control             *the_thread;
41  POSIX_API_Control                   *api;
42  Thread_CPU_budget_algorithms         budget_algorithm;
43  Thread_CPU_budget_algorithm_callout  budget_callout;
44  Objects_Locations                    location;
45  int                                  rc;
46
47  /*
48   *  Check all the parameters
49   */
50  if ( !param )
51    return EINVAL;
52
53  rc = _POSIX_Thread_Translate_sched_param(
54    policy,
55    param,
56    &budget_algorithm,
57    &budget_callout
58  );
59  if ( rc )
60    return rc;
61
62  /*
63   *  Actually change the scheduling policy and parameters
64   */
65  the_thread = _Thread_Get( thread, &location );
66  switch ( location ) {
67
68    case OBJECTS_LOCAL:
69      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
70
71      if ( api->schedpolicy == SCHED_SPORADIC )
72        (void) _Watchdog_Remove( &api->Sporadic_timer );
73
74      api->schedpolicy = policy;
75      api->schedparam  = *param;
76      the_thread->budget_algorithm = budget_algorithm;
77      the_thread->budget_callout   = budget_callout;
78
79      switch ( api->schedpolicy ) {
80        case SCHED_OTHER:
81        case SCHED_FIFO:
82        case SCHED_RR:
83          the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
84
85          the_thread->real_priority =
86            _POSIX_Priority_To_core( api->schedparam.sched_priority );
87
88          _Thread_Change_priority(
89             the_thread,
90             the_thread->real_priority,
91             true
92          );
93          break;
94
95        case SCHED_SPORADIC:
96          api->ss_high_priority = api->schedparam.sched_priority;
97          _Watchdog_Remove( &api->Sporadic_timer );
98          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
99          break;
100      }
101
102      _Objects_Put( &the_thread->Object );
103      return 0;
104
105#if defined(RTEMS_MULTIPROCESSING)
106    case OBJECTS_REMOTE:
107#endif
108    case OBJECTS_ERROR:
109      break;
110  }
111
112  return ESRCH;
113}
Note: See TracBrowser for help on using the repository browser.