source: rtems/c/src/tests/psxtests/psx11/task.c @ 60b791ad

4.104.114.84.95
Last change on this file since 60b791ad was 60b791ad, checked in by Joel Sherrill <joel.sherrill@…>, on 02/17/98 at 23:46:28

updated copyright to 1998

  • 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-1998.
12 *  On-Line Applications Research Corporation (OAR).
13 *  Copyright assigned to U.S. Government, 1994.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.OARcorp.com/rtems/license.html.
18 *
19 *  $Id$
20 */
21
22#include "system.h"
23#include <time.h>
24#include <sched.h>
25
26void diff_timespec(
27  struct timespec *start,
28  struct timespec *stop,
29  struct timespec *result
30)
31{
32   int nsecs_per_sec = 1000000000;
33 
34   result->tv_sec = stop->tv_sec - start->tv_sec;
35   if ( stop->tv_nsec < start->tv_nsec ) {
36      result->tv_nsec = nsecs_per_sec - start->tv_nsec + stop->tv_nsec;
37      result->tv_sec--;
38   } else
39      result->tv_nsec = stop->tv_nsec - start->tv_nsec;
40 
41}
42
43void *Task_1(
44  void *argument
45)
46{
47  int status;
48  struct timespec start;
49  struct timespec current;
50  struct timespec difference;
51  struct timespec delay;
52
53  status = clock_gettime( CLOCK_REALTIME, &start );
54  assert( !status );
55 
56  status = sched_rr_get_interval( getpid(), &delay );
57  assert( !status );
58
59  /* double the rr interval for confidence */
60
61  delay.tv_sec *= 2;
62  delay.tv_nsec *= 2;
63  if ( delay.tv_nsec >= 1000000000 ) {   /* handle overflow/carry */
64    delay.tv_nsec -= 1000000000;
65    delay.tv_sec++;
66  }
67   
68 
69  puts( "Task_1: killing time" );
70  for ( ; ; ) {
71
72    status = clock_gettime( CLOCK_REALTIME, &current );
73    assert( !status );
74
75    diff_timespec( &start, &current, &difference );
76
77    if ( difference.tv_sec < delay.tv_sec )
78      continue;
79
80    if ( difference.tv_sec > delay.tv_sec )
81      break;
82   
83    if ( difference.tv_nsec > delay.tv_nsec )
84      break;
85   
86  }
87
88  puts( "Task_1: exitting" );
89  pthread_exit( NULL );
90
91  return NULL; /* just so the compiler thinks we returned something */
92}
Note: See TracBrowser for help on using the repository browser.