source: rtems/testsuites/psxtests/psx11/init.c @ 98843fb8

4.104.11
Last change on this file since 98843fb8 was 98843fb8, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 25, 2009 at 5:46:40 PM

2009-10-25 Ralf Corsépius <ralf.corsepius@…>

  • psx11/init.c, psx09/init.c: Include <sched.h>.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2008.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <sched.h>
13
14#define CONFIGURE_INIT
15#include "system.h"
16#include <errno.h>
17
18void *POSIX_Init(
19  void *argument
20)
21{
22  int                  status;
23  struct sched_param   param;
24  pthread_attr_t       attr;
25  int                  priority_1;
26  int                  priority_2;
27  int                  priority_3;
28  int                  priority_4;
29
30  puts( "\n\n*** POSIX TEST 11 ***" );
31
32  /* set the time of day, and print our buffer in multiple ways */
33
34  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
35
36  /* get id of this thread */
37
38  Init_id = pthread_self();
39  printf( "Init's ID is 0x%08x\n", Init_id );
40
41  /* exercise pthread_setschedparam */
42
43  priority_1 = sched_get_priority_max( SCHED_FIFO );      /* was 127 */
44  priority_2 = sched_get_priority_max( SCHED_FIFO ) - 2;  /* was 125 */
45  priority_3 = sched_get_priority_max( SCHED_FIFO ) - 6;  /* was 121 */
46  priority_4 = sched_get_priority_max( SCHED_FIFO ) - 7;  /* was 120 */
47
48  param.sched_priority = priority_1;
49
50  printf(
51    "Init: Setting scheduling parameters to FIFO with priority %d\n",
52    priority_1
53  );
54  status = pthread_setschedparam( Init_id, SCHED_FIFO, &param );
55  assert( !status );
56
57  param.sched_priority = priority_2;
58
59  printf(
60    "Init: Setting scheduling parameters to RR with priority %d\n",
61    priority_2
62  );
63  status = pthread_setschedparam( Init_id, SCHED_RR, &param );
64  assert( !status );
65
66  param.sched_priority = priority_3;
67
68  printf(
69    "Init: Setting scheduling parameters to OTHER with priority %d\n",
70    priority_3
71  );
72  status = pthread_setschedparam( Init_id, SCHED_OTHER, &param );
73  assert( !status );
74
75  /* create a thread as SCHED_FIFO */
76
77  printf(
78    "Init: create a thread of SCHED_FIFO with priority %d\n", priority_4 );
79  status = pthread_attr_init( &attr );
80  assert( !status );
81
82  attr.schedpolicy = SCHED_FIFO;
83  attr.schedparam.sched_priority = priority_4;
84
85  status = pthread_create( &Task_id, &attr, Task_1, NULL );
86  assert( !status );
87
88  puts( "Init: join with the other thread" );
89  status = pthread_join( Task_id, NULL );
90  assert( !status );
91
92  /* create a thread as SCHED_RR */
93
94  printf( "Init: create a thread of SCHED_RR with priority %d\n", priority_4 );
95  status = pthread_attr_init( &attr );
96  assert( !status );
97
98  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
99  assert( !status );
100  attr.schedpolicy = SCHED_RR;
101  attr.schedparam.sched_priority = priority_4;
102
103  status = pthread_create( &Task_id, &attr, Task_1, NULL );
104  assert( !status );
105
106  puts( "Init: join with the other thread" );
107  status = pthread_join( Task_id, NULL );
108  assert( !status );
109
110  /* create a thread as SCHED_OTHER */
111
112  printf(
113    "Init: create a thread of SCHED_OTHER with priority %d\n", priority_4 );
114  status = pthread_attr_init( &attr );
115  assert( !status );
116
117  attr.schedpolicy = SCHED_OTHER;
118  attr.schedparam.sched_priority = priority_4;
119
120  status = pthread_create( &Task_id, &attr, Task_1, NULL );
121  assert( !status );
122
123  puts( "Init: join with the other thread" );
124  status = pthread_join( Task_id, NULL );
125  assert( !status );
126
127  puts( "*** END OF POSIX TEST 11 ***" );
128  rtems_test_exit( 0 );
129
130  return NULL; /* just so the compiler thinks we returned something */
131}
Note: See TracBrowser for help on using the repository browser.