Mercurial > ecos
annotate packages/kernel/current/tests/mutex2.cxx @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 2 | 1 //========================================================================== |
| 2 // | |
| 3 // mutex1.cxx | |
| 4 // | |
| 5 // Mutex test 1 | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
177
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
1507
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:
1507
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
1507
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:
1507
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
1507
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:
177
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
1507
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:
1507
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:
1507
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:
1507
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:
1507
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
177
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
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:
1507
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:
1507
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
1507
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 2 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): nickg | |
| 43 // Contributors: nickg | |
| 44 // Date: 1999-02-19 | |
| 45 // Description: Tests mutex release functionality | |
| 46 //####DESCRIPTIONEND#### | |
| 47 | |
| 48 #include <pkgconf/kernel.h> | |
| 49 | |
| 50 #include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start() | |
| 51 #include <cyg/kernel/thread.hxx> // Cyg_Thread | |
| 52 | |
| 53 #include <cyg/kernel/mutex.hxx> | |
| 54 | |
| 55 #include <cyg/infra/testcase.h> | |
| 56 | |
| 57 #include <cyg/kernel/sched.inl> | |
| 58 #include <cyg/kernel/thread.inl> | |
| 59 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
60 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
61 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
62 #if !defined(CYGPKG_KERNEL_SMP_SUPPORT) |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
63 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
64 // ------------------------------------------------------------------------ |
| 2 | 65 |
| 66 #define NTHREADS 4 | |
| 67 #include "testaux.hxx" | |
| 68 #include "testaux.h" | |
| 69 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
70 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
71 |
| 2 | 72 static Cyg_Mutex m0, m1; |
| 73 static Cyg_Condition_Variable cvar0( m0 ), cvar1( m0 ), cvar2( m1 ); | |
| 74 | |
| 75 volatile int thread_state[NTHREADS]; | |
| 76 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
77 // ------------------------------------------------------------------------ |
| 2 | 78 // This thread is meant to get hung up trying to re-acquire m0 |
| 79 // after waiting on the cv. | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
80 |
| 2 | 81 static void entry0( CYG_ADDRWORD data ) |
| 82 { | |
| 83 CYG_TEST_INFO( "thread0: lock mutex 0"); | |
| 84 | |
| 85 m0.lock(); | |
| 86 | |
| 87 CYG_TEST_INFO( "thread0: wait cvar 0"); | |
| 88 | |
| 89 thread_state[data] = 1; | |
| 90 | |
| 91 cvar0.wait(); | |
| 92 | |
| 93 thread_state[data] = 2; | |
| 94 | |
| 95 CYG_TEST_INFO( "thread0: woke from cvar 0"); | |
| 96 | |
| 97 CYG_TEST_INFO( "thread0: unlock mutex 0"); | |
| 98 | |
| 99 m0.unlock(); | |
| 100 | |
| 101 thread_state[data] = 3; | |
| 102 | |
| 103 CYG_TEST_INFO( "thread0: exit"); | |
| 104 | |
| 105 thread[data]->exit(); | |
| 106 } | |
| 107 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
108 // ------------------------------------------------------------------------ |
| 2 | 109 // This thread is meant to claim and keep m0. |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
110 |
| 2 | 111 static void entry1( CYG_ADDRWORD data ) |
| 112 { | |
| 113 CYG_TEST_INFO( "thread1: lock mutex 0"); | |
| 114 | |
| 115 m0.lock(); | |
| 116 | |
| 117 CYG_TEST_INFO( "thread1: lock mutex 1"); | |
| 118 | |
| 119 thread_state[data] = 1; | |
| 120 | |
| 121 m1.lock(); | |
| 122 | |
| 123 thread_state[data] = 2; | |
| 124 | |
| 125 CYG_TEST_INFO( "thread1: wait cvar 2"); | |
| 126 | |
| 127 cvar2.wait(); | |
| 128 | |
| 129 thread_state[data] = 3; | |
| 130 | |
| 131 CYG_TEST_INFO( "thread1: woke from cvar 2"); | |
| 132 | |
| 133 CYG_TEST_INFO( "thread1: unlock mutex 1"); | |
| 134 | |
| 135 m1.unlock(); | |
| 136 | |
| 137 thread_state[data] = 4; | |
| 138 | |
| 139 CYG_TEST_INFO( "thread1: unlock m0"); | |
| 140 | |
| 141 m0.unlock(); | |
| 142 | |
| 143 thread_state[data] = 5; | |
| 144 | |
| 145 CYG_TEST_INFO( "thread1: exit"); | |
| 146 | |
| 147 thread[data]->exit(); | |
| 148 } | |
| 149 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
150 // ------------------------------------------------------------------------ |
| 2 | 151 // This thread is meant to get hung trying to acquire m0, and then get |
| 152 // released out of it by thread3. | |
| 153 | |
| 154 static void entry2( CYG_ADDRWORD data ) | |
| 155 { | |
| 156 CYG_TEST_INFO( "thread2: lock mutex 0"); | |
| 157 | |
| 158 thread_state[data] = 1; | |
| 159 | |
| 160 if( m0.lock() ) | |
| 161 { | |
| 162 thread_state[data] = 2; | |
| 163 | |
| 164 CYG_TEST_INFO( "thread2: lock mutex 0 - returned TRUE"); | |
| 165 CYG_TEST_FAIL_FINISH(" m0.lock() returned TRUE" ); | |
| 166 } | |
| 167 else | |
| 168 { | |
| 169 thread_state[data] = 3; | |
| 170 CYG_TEST_INFO( "thread2: lock mutex 0 - returned FALSE"); | |
| 171 } | |
| 172 | |
| 173 CYG_TEST_INFO( "thread2: exit"); | |
| 174 | |
| 175 thread[data]->exit(); | |
| 176 } | |
| 177 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
178 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
179 |
| 2 | 180 static void entry3( CYG_ADDRWORD data ) |
| 181 { | |
| 182 | |
| 183 CHECK( thread_state[0] == 1 ); | |
| 184 CHECK( thread_state[1] == 2 ); | |
| 185 CHECK( thread_state[2] == 1 ); | |
| 186 | |
| 187 CYG_TEST_INFO( "thread3: signal cvar 0"); | |
| 188 | |
| 189 cvar0.signal(); | |
| 190 | |
| 191 CHECK( thread_state[0] == 1 ); | |
| 192 CHECK( thread_state[1] == 2 ); | |
| 193 CHECK( thread_state[2] == 1 ); | |
| 194 | |
| 195 CYG_TEST_INFO( "thread3: release mutex 0"); | |
| 196 | |
| 197 m0.release(); | |
| 198 | |
| 199 CHECK( thread_state[0] == 1 ); | |
| 200 CHECK( thread_state[1] == 2 ); | |
| 201 CHECK( thread_state[2] == 3 ); | |
| 202 | |
| 203 CYG_TEST_INFO( "thread3: signal cvar 2"); | |
| 204 | |
| 205 cvar2.signal(); | |
| 206 | |
| 207 CHECK( thread_state[0] == 3 ); | |
| 208 CHECK( thread_state[1] == 5 ); | |
| 209 CHECK( thread_state[2] == 3 ); | |
| 210 | |
| 211 CYG_TEST_PASS_FINISH( "mutex2 finished OK"); | |
| 212 | |
| 213 CYG_TEST_INFO( "thread3: exit"); | |
| 214 | |
| 215 thread[data]->exit(); | |
| 216 } | |
| 217 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
218 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
219 |
| 2 | 220 void mutex2_main( void ) |
| 221 { | |
| 222 CYG_TEST_INIT(); | |
| 223 | |
| 224 new_thread(entry0, 0); | |
| 225 new_thread(entry1, 1); | |
| 226 new_thread(entry2, 2); | |
| 227 new_thread(entry3, 3); | |
| 228 | |
| 229 // Set priorities from the top to prevent two threads getting | |
| 230 // the same priority: this causes an ASSERT on some configurations. | |
| 231 thread[3]->set_priority( 5 ); | |
| 232 thread[2]->set_priority( 4 ); | |
| 233 thread[1]->set_priority( 3 ); | |
| 234 thread[0]->set_priority( 2 ); | |
| 235 | |
| 236 Cyg_Scheduler::start(); | |
| 237 | |
| 238 CYG_TEST_FAIL_FINISH("Not reached"); | |
| 239 } | |
| 240 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
241 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
242 |
| 2 | 243 externC void |
| 244 cyg_start( void ) | |
| 245 { | |
|
130
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
246 #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
|
247 cyg_hal_invoke_constructors(); |
|
eb9fd8c04db3
Merge from eCos master repository on 2000-10-23-17:01:37-BST
jlarmour
parents:
66
diff
changeset
|
248 #endif |
| 2 | 249 mutex2_main(); |
| 250 } | |
| 251 | |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
252 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
253 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
254 #else // CYGPKG_KERNEL_SMP_SUPPORT |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
255 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
256 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
257 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
258 externC void |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
259 cyg_start( void ) |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
260 { |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
261 CYG_TEST_INIT(); |
| 1507 | 262 CYG_TEST_NA("Mutex2 test requires: !defined(CYGPKG_KERNEL_SMP_SUPPORT)"); |
|
177
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
263 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
264 } |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
265 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
266 // ------------------------------------------------------------------------ |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
267 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
268 #endif // CYGPKG_KERNEL_SMP_SUPPORT |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
269 |
|
4c750ce71ae3
Merge from eCos master repository on 2001-08-10-19:22:57-BST
jlarmour
parents:
130
diff
changeset
|
270 // ------------------------------------------------------------------------ |
| 2 | 271 // EOF mutex2.cxx |
