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 | |
---|
25 | void diff_timespec( |
---|
26 | struct timespec *start, |
---|
27 | struct timespec *stop, |
---|
28 | struct timespec *result |
---|
29 | ); |
---|
30 | |
---|
31 | void 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 | |
---|
48 | void *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, ¤t ); |
---|
78 | assert( !status ); |
---|
79 | |
---|
80 | diff_timespec( &start, ¤t, &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 | } |
---|