1 | /* |
---|
2 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * All rights assigned to U.S. Government, 1994. |
---|
5 | * |
---|
6 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
7 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
8 | * notice must appear in all copies of this file and its derivatives. |
---|
9 | * |
---|
10 | * $Id$ |
---|
11 | */ |
---|
12 | |
---|
13 | #define CONFIGURE_INIT |
---|
14 | #include "system.h" |
---|
15 | #include <sched.h> |
---|
16 | |
---|
17 | |
---|
18 | void *POSIX_Init( |
---|
19 | void *argument |
---|
20 | ) |
---|
21 | { |
---|
22 | int status; |
---|
23 | int priority; |
---|
24 | pthread_t thread_id; |
---|
25 | time_t seconds; |
---|
26 | time_t remaining; |
---|
27 | struct tm tm; |
---|
28 | struct timespec tv; |
---|
29 | struct timespec tr; |
---|
30 | |
---|
31 | puts( "\n\n*** POSIX TEST 1 ***" ); |
---|
32 | |
---|
33 | /* set the time of day, and print our buffer in multiple ways */ |
---|
34 | |
---|
35 | build_time( &tm, TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); |
---|
36 | |
---|
37 | tv.tv_sec = mktime( &tm ); |
---|
38 | assert( tv.tv_sec != -1 ); |
---|
39 | |
---|
40 | tv.tv_nsec = 0; |
---|
41 | |
---|
42 | status = clock_settime( CLOCK_REALTIME, &tv ); |
---|
43 | assert( !status ); |
---|
44 | |
---|
45 | printf( asctime( &tm ) ); |
---|
46 | printf( ctime( &tv.tv_sec ) ); |
---|
47 | |
---|
48 | /* use sleep to delay */ |
---|
49 | |
---|
50 | remaining = sleep( 3 ); |
---|
51 | assert( !remaining ); |
---|
52 | |
---|
53 | /* print new times to make sure it has changed and we can get the realtime */ |
---|
54 | |
---|
55 | status = clock_gettime( CLOCK_REALTIME, &tv ); |
---|
56 | assert( !status ); |
---|
57 | |
---|
58 | printf( ctime( &tv.tv_sec ) ); |
---|
59 | |
---|
60 | seconds = time( NULL ); |
---|
61 | printf( ctime( &seconds ) ); |
---|
62 | |
---|
63 | /* check the time remaining */ |
---|
64 | |
---|
65 | printf( "Init: seconds remaining (%d)\n", (int)remaining ); |
---|
66 | assert( !remaining ); |
---|
67 | |
---|
68 | /* use nanosleep to delay */ |
---|
69 | |
---|
70 | tv.tv_sec = 3; |
---|
71 | tv.tv_nsec = 500000; |
---|
72 | |
---|
73 | status = nanosleep ( &tv, &tr ); |
---|
74 | assert( !status ); |
---|
75 | |
---|
76 | /* print the current real time again */ |
---|
77 | |
---|
78 | status = clock_gettime( CLOCK_REALTIME, &tv ); |
---|
79 | assert( !status ); |
---|
80 | |
---|
81 | printf( ctime( &tv.tv_sec ) ); |
---|
82 | |
---|
83 | /* check the time remaining */ |
---|
84 | |
---|
85 | printf( "Init: sec (%ld), nsec (%ld) remaining\n", tr.tv_sec, tr.tv_nsec ); |
---|
86 | assert( !tr.tv_sec && !tr.tv_nsec ); |
---|
87 | |
---|
88 | /* get id of this thread */ |
---|
89 | |
---|
90 | Init_id = pthread_self(); |
---|
91 | printf( "Init: ID is 0x%08x\n", Init_id ); |
---|
92 | |
---|
93 | /* print the minimum priority */ |
---|
94 | |
---|
95 | priority = sched_get_priority_min( SCHED_FIFO ); |
---|
96 | printf( "Init: Minimum priority for FIFO is %d\n", priority ); |
---|
97 | assert( priority != -1 ); |
---|
98 | |
---|
99 | /* print the maximum priority */ |
---|
100 | |
---|
101 | priority = sched_get_priority_max( SCHED_FIFO ); |
---|
102 | printf( "Init: Maximum priority for FIFO is %d\n", priority ); |
---|
103 | assert( priority != -1 ); |
---|
104 | |
---|
105 | /* print the round robin time quantum */ |
---|
106 | |
---|
107 | status = sched_rr_get_interval( getpid(), &tr ); |
---|
108 | printf( |
---|
109 | "Init: Round Robin quantum is %ld seconds, %ld nanoseconds\n", |
---|
110 | tr.tv_sec, |
---|
111 | tr.tv_nsec |
---|
112 | ); |
---|
113 | assert( !status ); |
---|
114 | |
---|
115 | /* create a thread */ |
---|
116 | |
---|
117 | status = pthread_create( &thread_id, NULL, Task_1_through_3, NULL ); |
---|
118 | assert( !status ); |
---|
119 | |
---|
120 | /* exit this thread */ |
---|
121 | |
---|
122 | pthread_exit( NULL ); |
---|
123 | |
---|
124 | return NULL; /* just so the compiler thinks we returned something */ |
---|
125 | } |
---|