Mercurial > ecos
comparison packages/kernel/current/tests/sync2.cxx @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | c38311975d4f |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 20 // | 20 // |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | 21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 22 // September 30, 1998. | 22 // September 30, 1998. |
| 23 // | 23 // |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | 24 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 26 // ------------------------------------------- | 26 // ------------------------------------------- |
| 27 // | 27 // |
| 28 //####COPYRIGHTEND#### | 28 //####COPYRIGHTEND#### |
| 29 //========================================================================== | 29 //========================================================================== |
| 30 //#####DESCRIPTIONBEGIN#### | 30 //#####DESCRIPTIONBEGIN#### |
| 69 static cyg_ucount8 m0d=99, sd=2, cd0=99, cd1=99; | 69 static cyg_ucount8 m0d=99, sd=2, cd0=99, cd1=99; |
| 70 | 70 |
| 71 static void entry0( CYG_ADDRWORD data ) | 71 static void entry0( CYG_ADDRWORD data ) |
| 72 { | 72 { |
| 73 for(cyg_ucount16 i=0; i<n; i++) { | 73 for(cyg_ucount16 i=0; i<n; i++) { |
| 74 s2.wait(); | 74 s2.wait(); |
| 75 CHECK( 2 == sd ); | 75 CHECK( 2 == sd ); |
| 76 sd = 0; | 76 sd = 0; |
| 77 m0.lock(); { | 77 m0.lock(); { |
| 78 m0d = 0; | 78 m0d = 0; |
| 79 s0.post(); | 79 s0.post(); |
| 80 CHECK( 0 == m0d ); | 80 CHECK( 0 == m0d ); |
| 81 } m0.unlock(); | 81 } m0.unlock(); |
| 82 } | 82 } |
| 83 // wait for 3 explicit posts to indicate threads have stopped. | 83 // wait for 3 explicit posts to indicate threads have stopped. |
| 84 for(cyg_ucount8 i=0; i<3; i++) | 84 for(cyg_ucount8 i=0; i<3; i++) |
| 85 cs3.wait(); | 85 cs3.wait(); |
| 86 | 86 |
| 87 CHECK( ! s0.posted() ); | 87 CHECK( ! s0.posted() ); |
| 88 CHECK( ! s1.posted() ); | 88 CHECK( ! s1.posted() ); |
| 89 CHECK( s2.posted() ); | 89 CHECK( s2.posted() ); |
| 90 | 90 |
| 100 } | 100 } |
| 101 | 101 |
| 102 static void entry1( CYG_ADDRWORD data ) | 102 static void entry1( CYG_ADDRWORD data ) |
| 103 { | 103 { |
| 104 for(cyg_ucount16 i=0; i<n; i++) { | 104 for(cyg_ucount16 i=0; i<n; i++) { |
| 105 s0.wait(); | 105 s0.wait(); |
| 106 CHECK( 0 == sd ); | 106 CHECK( 0 == sd ); |
| 107 sd = 1; | 107 sd = 1; |
| 108 cd0 = 1; | 108 cd0 = 1; |
| 109 cs1.post(); | 109 cs1.post(); |
| 110 cd1 = 1; | 110 cd1 = 1; |
| 111 cs1.post(); | 111 cs1.post(); |
| 112 s1.post(); | 112 s1.post(); |
| 113 cs0.wait(); | 113 cs0.wait(); |
| 114 CHECK( 0 == cd0 ); | 114 CHECK( 0 == cd0 ); |
| 115 cs0.wait(); | 115 cs0.wait(); |
| 116 CHECK( 0 == cd1 ); | 116 CHECK( 0 == cd1 ); |
| 117 } | 117 } |
| 118 cs3.post(); | 118 cs3.post(); |
| 119 s0.wait(); | 119 s0.wait(); |
| 120 CYG_TEST_FAIL_FINISH("Not reached"); | 120 CYG_TEST_FAIL_FINISH("Not reached"); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static void entry2( CYG_ADDRWORD data ) | 123 static void entry2( CYG_ADDRWORD data ) |
| 124 { | 124 { |
| 125 for(cyg_ucount16 i=0; i<n; i++) { | 125 for(cyg_ucount16 i=0; i<n; i++) { |
| 126 s1.wait(); | 126 s1.wait(); |
| 127 CHECK( 1 == sd ); | 127 CHECK( 1 == sd ); |
| 128 sd = 2; | 128 sd = 2; |
| 129 cs1.wait(); | 129 cs1.wait(); |
| 130 CHECK( 1 == cd0 ); | 130 CHECK( 1 == cd0 ); |
| 131 cd0 = 2; | 131 cd0 = 2; |
| 132 cs2.post(); | 132 cs2.post(); |
| 133 s2.post(); | 133 s2.post(); |
| 134 cs1.wait(); | 134 cs1.wait(); |
| 135 CHECK( 1 == cd1 ); | 135 CHECK( 1 == cd1 ); |
| 136 cd1 = 2; | 136 cd1 = 2; |
| 137 cs2.post(); | 137 cs2.post(); |
| 138 } | 138 } |
| 139 cs3.post(); | 139 cs3.post(); |
| 140 s1.wait(); | 140 s1.wait(); |
| 141 CYG_TEST_FAIL_FINISH("Not reached"); | 141 CYG_TEST_FAIL_FINISH("Not reached"); |
| 142 } | 142 } |
| 143 | 143 |
| 144 static void entry3( CYG_ADDRWORD data ) | 144 static void entry3( CYG_ADDRWORD data ) |
| 145 { | 145 { |
| 146 for(cyg_ucount16 i=0; i < n*2; i++) { | 146 for(cyg_ucount16 i=0; i < n*2; i++) { |
| 147 cs2.wait(); | 147 cs2.wait(); |
| 148 CHECK( 2 == cd0 || 2 == cd1 ); | 148 CHECK( 2 == cd0 || 2 == cd1 ); |
| 149 m0.lock(); { | 149 m0.lock(); { |
| 150 m0d = 3; | 150 m0d = 3; |
| 151 if( 2 == cd0 ) | 151 if( 2 == cd0 ) |
| 152 cd0 = 0; | 152 cd0 = 0; |
| 153 else { | 153 else { |
| 154 CHECK( 2 == cd1 ); | 154 CHECK( 2 == cd1 ); |
| 155 cd1 = 0; | 155 cd1 = 0; |
| 156 } | 156 } |
| 157 cs0.post(); | 157 cs0.post(); |
| 158 CHECK( 3 == m0d ); | 158 CHECK( 3 == m0d ); |
| 159 } m0.unlock(); | 159 } m0.unlock(); |
| 160 } | 160 } |
| 161 cs3.post(); | 161 cs3.post(); |
| 162 cs1.wait(); | 162 cs1.wait(); |
| 163 CYG_TEST_FAIL_FINISH("Not reached"); | 163 CYG_TEST_FAIL_FINISH("Not reached"); |
| 164 } | 164 } |
