source: rtems/testsuites/psxtests/psx11/task.c @ 2e7e636f

4.104.115
Last change on this file since 2e7e636f was 2e7e636f, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/09 at 01:41:16

2009-05-10 Joel Sherrill <joel.sherrill@…>

  • psx01/init.c, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx04/task1.c, psx04/task3.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/init.c, psx09/init.c, psx11/task.c, psx12/init.c, psx13/main.c, psx13/test.c, psxbarrier01/test.c, psxcancel/init.c, psxcleanup/psxcleanup.c, psxenosys/init.c, psxmsgq02/init.c, psxtime/main.c, psxtime/test.c, psxtimer01/psxtimer.c, psxtimer02/psxtimer.c: Fix warnings.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  Task_1
2 *
3 *  This routine serves as a test task.  It verifies the basic task
4 *  switching capabilities of the executive.
5 *
6 *  Input parameters:
7 *    argument - task argument
8 *
9 *  Output parameters:  NONE
10 *
11 *  COPYRIGHT (c) 1989-2009.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include "system.h"
22#include <time.h>
23#include <sched.h>
24
25void diff_timespec(
26  struct timespec *start,
27  struct timespec *stop,
28  struct timespec *result
29);
30
31void diff_timespec(
32  struct timespec *start,
33  struct timespec *stop,
34  struct timespec *result
35)
36{
37   int nsecs_per_sec = 1000000000;
38
39   result->tv_sec = stop->tv_sec - start->tv_sec;
40   if ( stop->tv_nsec < start->tv_nsec ) {
41      result->tv_nsec = nsecs_per_sec - start->tv_nsec + stop->tv_nsec;
42      result->tv_sec--;
43   } else
44      result->tv_nsec = stop->tv_nsec - start->tv_nsec;
45
46}
47
48void *Task_1(
49  void *argument
50)
51{
52  int status;
53  struct timespec start;
54  struct timespec current;
55  struct timespec difference;
56  struct timespec delay;
57
58  status = clock_gettime( CLOCK_REALTIME, &start );
59  assert( !status );
60
61  status = sched_rr_get_interval( getpid(), &delay );
62  assert( !status );
63
64  /* double the rr interval for confidence */
65
66  delay.tv_sec *= 2;
67  delay.tv_nsec *= 2;
68  if ( delay.tv_nsec >= 1000000000 ) {   /* handle overflow/carry */
69    delay.tv_nsec -= 1000000000;
70    delay.tv_sec++;
71  }
72
73
74  puts( "Task_1: killing time" );
75  for ( ; ; ) {
76
77    status = clock_gettime( CLOCK_REALTIME, &current );
78    assert( !status );
79
80    diff_timespec( &start, &current, &difference );
81
82    if ( difference.tv_sec < delay.tv_sec )
83      continue;
84
85    if ( difference.tv_sec > delay.tv_sec )
86      break;
87
88    if ( difference.tv_nsec > delay.tv_nsec )
89      break;
90
91  }
92
93  puts( "Task_1: exitting" );
94  pthread_exit( NULL );
95
96  return NULL; /* just so the compiler thinks we returned something */
97}
Note: See TracBrowser for help on using the repository browser.