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

4.115
Last change on this file since 2903090 was 2903090, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/15 at 09:26:46

score: Add header to _Watchdog_Remove()

Add watchdog header parameter to _Watchdog_Remove() to be in line with
the other operations. Add _Watchdog_Remove_ticks() and
_Watchdog_Remove_seconds() for convenience.

Update #2307.

  • Property mode set to 100644
File size: 2.8 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-2014.
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.org/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/posix/pthreadimpl.h>
29#include <rtems/posix/priorityimpl.h>
30#include <rtems/posix/time.h>
31#include <rtems/score/threadimpl.h>
32#include <rtems/score/watchdogimpl.h>
33#include <rtems/config.h>
34
35int pthread_setschedparam(
36  pthread_t           thread,
37  int                 policy,
38  struct sched_param *param
39)
40{
41  Thread_Control                      *the_thread;
42  POSIX_API_Control                   *api;
43  Thread_CPU_budget_algorithms         budget_algorithm;
44  Thread_CPU_budget_algorithm_callout  budget_callout;
45  Objects_Locations                    location;
46  int                                  rc;
47
48  /*
49   *  Check all the parameters
50   */
51  if ( !param )
52    return EINVAL;
53
54  rc = _POSIX_Thread_Translate_sched_param(
55    policy,
56    param,
57    &budget_algorithm,
58    &budget_callout
59  );
60  if ( rc )
61    return rc;
62
63  /*
64   *  Actually change the scheduling policy and parameters
65   */
66  the_thread = _Thread_Get( thread, &location );
67  switch ( location ) {
68
69    case OBJECTS_LOCAL:
70      api = the_thread->API_Extensions[ THREAD_API_POSIX ];
71
72      if ( api->schedpolicy == SCHED_SPORADIC )
73        _Watchdog_Remove_ticks( &api->Sporadic_timer );
74
75      api->schedpolicy = policy;
76      api->schedparam  = *param;
77      api->Attributes.schedpolicy = policy;
78      api->Attributes.schedparam  = *param;
79
80      the_thread->budget_algorithm = budget_algorithm;
81      the_thread->budget_callout   = budget_callout;
82
83      switch ( api->schedpolicy ) {
84        case SCHED_OTHER:
85        case SCHED_FIFO:
86        case SCHED_RR:
87          the_thread->cpu_time_budget =
88            rtems_configuration_get_ticks_per_timeslice();
89
90          the_thread->real_priority =
91            _POSIX_Priority_To_core( api->schedparam.sched_priority );
92
93          _Thread_Change_priority(
94             the_thread,
95             the_thread->real_priority,
96             true
97          );
98          break;
99
100        case SCHED_SPORADIC:
101          api->ss_high_priority = api->schedparam.sched_priority;
102          _Watchdog_Remove_ticks( &api->Sporadic_timer );
103          _POSIX_Threads_Sporadic_budget_TSR( 0, the_thread );
104          break;
105      }
106
107      _Objects_Put( &the_thread->Object );
108      return 0;
109
110#if defined(RTEMS_MULTIPROCESSING)
111    case OBJECTS_REMOTE:
112#endif
113    case OBJECTS_ERROR:
114      break;
115  }
116
117  return ESRCH;
118}
Note: See TracBrowser for help on using the repository browser.