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, 1990, 1991, 1992, 1993, 1994. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * All rights assigned to U.S. Government, 1994. |
---|
14 | * |
---|
15 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
16 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
17 | * notice must appear in all copies of this file and its derivatives. |
---|
18 | * |
---|
19 | * $Id$ |
---|
20 | */ |
---|
21 | |
---|
22 | #include "system.h" |
---|
23 | #include <time.h> |
---|
24 | #include <sched.h> |
---|
25 | |
---|
26 | void 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 | |
---|
43 | void *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, ¤t ); |
---|
73 | assert( !status ); |
---|
74 | |
---|
75 | diff_timespec( &start, ¤t, &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 | } |
---|