1 | /* Test_task2 |
---|
2 | * |
---|
3 | * This task attempts to receive control of a global semaphore. |
---|
4 | * If running on the node on which the semaphore resides, the wait is |
---|
5 | * forever, otherwise it times out on a remote semaphore. |
---|
6 | * |
---|
7 | * Input parameters: |
---|
8 | * argument - task argument |
---|
9 | * |
---|
10 | * Output parameters: NONE |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * All rights assigned to U.S. Government, 1994. |
---|
15 | * |
---|
16 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
17 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
18 | * notice must appear in all copies of this file and its derivatives. |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | |
---|
23 | #include "system.h" |
---|
24 | |
---|
25 | rtems_task Test_task2( |
---|
26 | rtems_task_argument argument |
---|
27 | ) |
---|
28 | { |
---|
29 | rtems_status_code status; |
---|
30 | |
---|
31 | puts( "Getting SMID of semaphore" ); |
---|
32 | do { |
---|
33 | status = rtems_semaphore_ident( |
---|
34 | Semaphore_name[ 1 ], |
---|
35 | RTEMS_SEARCH_ALL_NODES, |
---|
36 | &Semaphore_id[ 1 ] |
---|
37 | ); |
---|
38 | } while ( !rtems_is_status_successful( status ) ); |
---|
39 | |
---|
40 | directive_failed( status, "rtems_semaphore_ident" ); |
---|
41 | |
---|
42 | if ( Multiprocessing_configuration.node == 1 ) { |
---|
43 | status = rtems_task_wake_after( TICKS_PER_SECOND ); |
---|
44 | directive_failed( status, "rtems_task_wake_after" ); |
---|
45 | |
---|
46 | puts( "Releasing semaphore ..." ); |
---|
47 | status = rtems_semaphore_release( Semaphore_id[ 1 ] ); |
---|
48 | directive_failed( status, "rtems_semaphore_release" ); |
---|
49 | |
---|
50 | status = rtems_task_wake_after( TICKS_PER_SECOND / 2 ); |
---|
51 | directive_failed( status, "rtems_task_wake_after" ); |
---|
52 | |
---|
53 | puts( "Getting semaphore ..." ); |
---|
54 | status = rtems_semaphore_obtain( |
---|
55 | Semaphore_id[ 1 ], |
---|
56 | RTEMS_DEFAULT_OPTIONS, |
---|
57 | RTEMS_NO_TIMEOUT |
---|
58 | ); |
---|
59 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
60 | |
---|
61 | puts( "Getting semaphore ..." ); |
---|
62 | status = rtems_semaphore_obtain( |
---|
63 | Semaphore_id[ 1 ], |
---|
64 | RTEMS_DEFAULT_OPTIONS, |
---|
65 | RTEMS_NO_TIMEOUT |
---|
66 | ); |
---|
67 | puts( "How did I get back from here????" ); |
---|
68 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
69 | } |
---|
70 | |
---|
71 | /* |
---|
72 | status = rtems_task_wake_after( TICKS_PER_SECOND / 2 ); |
---|
73 | directive_failed( status, "rtems_task_wake_after" ); |
---|
74 | */ |
---|
75 | |
---|
76 | puts( "Getting semaphore ..." ); |
---|
77 | status = rtems_semaphore_obtain( |
---|
78 | Semaphore_id[ 1 ], |
---|
79 | RTEMS_DEFAULT_OPTIONS, |
---|
80 | RTEMS_NO_TIMEOUT |
---|
81 | ); |
---|
82 | directive_failed( status, "rtems_semaphore_obtain" ); |
---|
83 | |
---|
84 | puts( "Releasing semaphore ..." ); |
---|
85 | status = rtems_semaphore_release( Semaphore_id[ 1 ] ); |
---|
86 | directive_failed( status, "rtems_semaphore_release" ); |
---|
87 | |
---|
88 | status = rtems_task_wake_after( TICKS_PER_SECOND ); |
---|
89 | directive_failed( status, "rtems_task_wake_after" ); |
---|
90 | |
---|
91 | puts( "Getting semaphore ..." ); |
---|
92 | status = rtems_semaphore_obtain( |
---|
93 | Semaphore_id[ 1 ], |
---|
94 | RTEMS_DEFAULT_OPTIONS, |
---|
95 | 2 * TICKS_PER_SECOND |
---|
96 | ); |
---|
97 | fatal_directive_status( |
---|
98 | status, |
---|
99 | RTEMS_TIMEOUT, |
---|
100 | "rtems_semaphore_obtain" |
---|
101 | ); |
---|
102 | puts( "rtems_semaphore_obtain correctly returned RTEMS_TIMEOUT" ); |
---|
103 | |
---|
104 | puts( "*** END OF TEST 13 ***" ); |
---|
105 | exit( 0 ); |
---|
106 | } |
---|