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

4.115
Last change on this file since be1b8a7 was 0c5317d, checked in by Sebastian Huber <sebastian.huber@…>, on 07/19/13 at 12:33:56

posix: Create pthread implementation header

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

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * @file
3 *
4 * @brief Translate sched_param into SuperCore Terms
5 * @ingroup POSIX_PTHREAD Private POSIX Threads
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22#include <errno.h>
23
24#include <rtems/system.h>
25#include <rtems/posix/pthreadimpl.h>
26#include <rtems/posix/priorityimpl.h>
27#include <rtems/posix/time.h>
28
29int _POSIX_Thread_Translate_sched_param(
30  int                                  policy,
31  struct sched_param                  *param,
32  Thread_CPU_budget_algorithms        *budget_algorithm,
33  Thread_CPU_budget_algorithm_callout *budget_callout
34)
35{
36  if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
37    return EINVAL;
38
39  *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
40  *budget_callout = NULL;
41
42  if ( policy == SCHED_OTHER ) {
43    *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
44    return 0;
45  }
46
47  if ( policy == SCHED_FIFO ) {
48    *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
49    return 0;
50  }
51
52  if ( policy == SCHED_RR ) {
53    *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
54    return 0;
55  }
56
57  if ( policy == SCHED_SPORADIC ) {
58    if ( (param->sched_ss_repl_period.tv_sec == 0) &&
59         (param->sched_ss_repl_period.tv_nsec == 0) )
60      return EINVAL;
61
62    if ( (param->sched_ss_init_budget.tv_sec == 0) &&
63         (param->sched_ss_init_budget.tv_nsec == 0) )
64      return EINVAL;
65
66    if ( _Timespec_To_ticks( &param->sched_ss_repl_period ) <
67         _Timespec_To_ticks( &param->sched_ss_init_budget ) )
68      return EINVAL;
69
70    if ( !_POSIX_Priority_Is_valid( param->sched_ss_low_priority ) )
71      return EINVAL;
72
73    *budget_algorithm  = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
74    *budget_callout = _POSIX_Threads_Sporadic_budget_callout;
75    return 0;
76  }
77
78  return EINVAL;
79}
Note: See TracBrowser for help on using the repository browser.