Mercurial > nand-ecoscentric
annotate packages/kernel/current/tests/sync2.cxx @ 3403:8c8767bb9a62 default tip
devs/nand/micron_mt29: Remove defunct references (in comments) to mt29f2g08_oob_ecc.
| author | Ross Younger <wry@ecoscentric.com> |
|---|---|
| date | Sun, 18 Jan 2015 17:59:01 +1300 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 3 // sync2.cxx | |
| 4 // | |
| 5 // Sync test 2 -- test of different locking mechanisms | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
130
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): dsm | |
| 43 // Contributors: dsm | |
| 44 // Date: 1998-02-18 | |
| 45 // Description: | |
| 46 // Creates some threads and tests the various synchronization | |
| 47 // mechanisms. Four threads are created t0..t3. t0 and t3 grab a | |
| 48 // mutex and check they have exclusive access to shared variable. | |
| 49 // t0,t1,t2 post each other in a loop with a semaphore so that | |
| 50 // only one is running at any time. t1,t2,t3 do a similar thing | |
| 51 // with counting semaphores, except that there are two active | |
| 52 // threads. | |
| 53 // Omissions: | |
| 54 // Doesn't test condition variables | |
| 55 // | |
| 56 //####DESCRIPTIONEND#### | |
| 57 | |
| 58 #include <pkgconf/kernel.h> | |
| 59 | |
| 60 #include <cyg/kernel/thread.hxx> | |
| 61 #include <cyg/kernel/thread.inl> | |
| 62 #include <cyg/kernel/sched.hxx> | |
| 63 #include <cyg/kernel/mutex.hxx> | |
| 64 #include <cyg/kernel/sema.hxx> | |
| 65 | |
| 66 #include <cyg/infra/testcase.h> | |
| 67 | |
| 68 #include <cyg/kernel/sched.inl> | |
| 69 | |
| 70 #define NTHREADS 4 | |
| 71 | |
| 72 #include "testaux.hxx" | |
| 73 | |
| 74 static Cyg_Mutex m0; | |
| 75 static Cyg_Binary_Semaphore s0, s1, s2(1); | |
| 76 static Cyg_Counting_Semaphore cs0, cs1, cs2, cs3; | |
| 77 | |
| 78 static const cyg_ucount16 n = 1000; | |
| 79 static cyg_ucount8 m0d=99, sd=2, cd0=99, cd1=99; | |
| 80 | |
| 81 static void entry0( CYG_ADDRWORD data ) | |
| 82 { | |
| 83 for(cyg_ucount16 i=0; i<n; i++) { | |
| 2 | 84 s2.wait(); |
| 85 CHECK( 2 == sd ); | |
| 86 sd = 0; | |
| 87 m0.lock(); { | |
| 88 m0d = 0; | |
| 89 s0.post(); | |
| 90 CHECK( 0 == m0d ); | |
| 91 } m0.unlock(); | |
| 0 | 92 } |
| 93 // wait for 3 explicit posts to indicate threads have stopped. | |
| 94 for(cyg_ucount8 i=0; i<3; i++) | |
| 2 | 95 cs3.wait(); |
| 0 | 96 |
| 97 CHECK( ! s0.posted() ); | |
| 98 CHECK( ! s1.posted() ); | |
| 99 CHECK( s2.posted() ); | |
| 100 | |
| 101 CHECK( 0 == cs0.peek() ); | |
| 102 CHECK( 0 == cs1.peek() ); | |
| 103 CHECK( 0 == cs2.peek() ); | |
| 104 CHECK( 0 == cs3.peek() ); | |
| 105 | |
| 106 CHECK( 0 == cd0 ); | |
| 107 CHECK( 0 == cd1 ); | |
| 108 CYG_TEST_PASS_FINISH("Sync 2 OK"); | |
| 109 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 110 } | |
| 111 | |
| 112 static void entry1( CYG_ADDRWORD data ) | |
| 113 { | |
| 114 for(cyg_ucount16 i=0; i<n; i++) { | |
| 2 | 115 s0.wait(); |
| 116 CHECK( 0 == sd ); | |
| 117 sd = 1; | |
| 118 cd0 = 1; | |
| 119 cs1.post(); | |
| 120 cd1 = 1; | |
| 121 cs1.post(); | |
| 122 s1.post(); | |
| 123 cs0.wait(); | |
| 124 CHECK( 0 == cd0 ); | |
| 125 cs0.wait(); | |
| 126 CHECK( 0 == cd1 ); | |
| 0 | 127 } |
| 128 cs3.post(); | |
| 129 s0.wait(); | |
| 130 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 131 } | |
| 132 | |
| 133 static void entry2( CYG_ADDRWORD data ) | |
| 134 { | |
| 135 for(cyg_ucount16 i=0; i<n; i++) { | |
| 2 | 136 s1.wait(); |
| 137 CHECK( 1 == sd ); | |
| 138 sd = 2; | |
| 139 cs1.wait(); | |
| 140 CHECK( 1 == cd0 ); | |
| 141 cd0 = 2; | |
| 142 cs2.post(); | |
| 143 s2.post(); | |
| 144 cs1.wait(); | |
| 145 CHECK( 1 == cd1 ); | |
| 146 cd1 = 2; | |
| 147 cs2.post(); | |
| 0 | 148 } |
| 149 cs3.post(); | |
| 150 s1.wait(); | |
| 151 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 152 } | |
| 153 | |
| 154 static void entry3( CYG_ADDRWORD data ) | |
| 155 { | |
| 156 for(cyg_ucount16 i=0; i < n*2; i++) { | |
| 2 | 157 cs2.wait(); |
| 158 CHECK( 2 == cd0 || 2 == cd1 ); | |
| 159 m0.lock(); { | |
| 160 m0d = 3; | |
| 161 if( 2 == cd0 ) | |
| 162 cd0 = 0; | |
| 163 else { | |
| 164 CHECK( 2 == cd1 ); | |
| 165 cd1 = 0; | |
| 166 } | |
| 167 cs0.post(); | |
| 168 CHECK( 3 == m0d ); | |
| 169 } m0.unlock(); | |
| 0 | 170 } |
| 171 cs3.post(); | |
| 172 cs1.wait(); | |
| 173 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 174 } | |
| 175 | |
| 176 | |
| 177 void sync2_main(void) | |
| 178 { | |
| 179 CYG_TEST_INIT(); | |
| 180 | |
| 181 new_thread(entry0, 0); | |
| 182 new_thread(entry1, 1); | |
| 183 new_thread(entry2, 2); | |
| 184 new_thread(entry3, 3); | |
| 185 | |
| 186 Cyg_Scheduler::start(); | |
| 187 | |
| 188 CYG_TEST_PASS_FINISH("Not reached"); | |
| 189 } | |
| 190 | |
| 191 externC void | |
| 192 cyg_start( void ) | |
| 193 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
194 #ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
195 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
196 #endif |
| 0 | 197 sync2_main(); |
| 198 } | |
| 199 | |
| 200 // EOF sync2.cxx |
