1 |
1254 |
phoenix |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// thread2.cxx
|
4 |
|
|
//
|
5 |
|
|
// Thread test 2
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): dsm
|
44 |
|
|
// Contributors: dsm
|
45 |
|
|
// Date: 1998-02-19
|
46 |
|
|
// Description:
|
47 |
|
|
// tests scheduler & threads & priorities
|
48 |
|
|
// + create multiple threads with various priorities
|
49 |
|
|
// + check highest priority running thread is always running
|
50 |
|
|
// + check next highest runs when highest suspended
|
51 |
|
|
// + check several threads of equal priority share time
|
52 |
|
|
// (only !CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES)
|
53 |
|
|
// + check other threads are starved
|
54 |
|
|
// + check setting priority dynamically causes a thread to
|
55 |
|
|
// become/stay current/non-current
|
56 |
|
|
// Omissions:
|
57 |
|
|
// check yield
|
58 |
|
|
// check can set threads with min and max priority
|
59 |
|
|
// Options:
|
60 |
|
|
// CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES
|
61 |
|
|
// CYGIMP_THREAD_PRIORITY
|
62 |
|
|
// CYGNUM_KERNEL_SCHED_PRIORITIES
|
63 |
|
|
// CYGSEM_KERNEL_SCHED_BITMAP
|
64 |
|
|
// CYGSEM_KERNEL_SCHED_MLQUEUE
|
65 |
|
|
//####DESCRIPTIONEND####
|
66 |
|
|
//==========================================================================
|
67 |
|
|
|
68 |
|
|
#include <pkgconf/kernel.h>
|
69 |
|
|
|
70 |
|
|
#include <cyg/kernel/thread.hxx>
|
71 |
|
|
#include <cyg/kernel/thread.inl>
|
72 |
|
|
#include <cyg/kernel/sched.hxx>
|
73 |
|
|
#include <cyg/kernel/mutex.hxx>
|
74 |
|
|
#include <cyg/kernel/sema.hxx>
|
75 |
|
|
|
76 |
|
|
#include <cyg/infra/testcase.h>
|
77 |
|
|
|
78 |
|
|
#include <cyg/kernel/sched.inl>
|
79 |
|
|
|
80 |
|
|
// ------------------------------------------------------------------------
|
81 |
|
|
|
82 |
|
|
#if defined(CYGIMP_THREAD_PRIORITY) && \
|
83 |
|
|
!defined(CYGPKG_KERNEL_SMP_SUPPORT)
|
84 |
|
|
|
85 |
|
|
// ------------------------------------------------------------------------
|
86 |
|
|
|
87 |
|
|
static Cyg_Counting_Semaphore s0, s1, s2;
|
88 |
|
|
|
89 |
|
|
static volatile cyg_ucount8 q = 0;
|
90 |
|
|
|
91 |
|
|
static Cyg_Thread *thread0, *thread1, *thread2;
|
92 |
|
|
|
93 |
|
|
#define NTHREADS 3
|
94 |
|
|
#include "testaux.hxx"
|
95 |
|
|
|
96 |
|
|
// ------------------------------------------------------------------------
|
97 |
|
|
|
98 |
|
|
static void entry0( CYG_ADDRWORD data )
|
99 |
|
|
{
|
100 |
|
|
CHECK( 0 == q++ );
|
101 |
|
|
s0.wait();
|
102 |
|
|
CHECK( 3 == q++ );
|
103 |
|
|
s1.post();
|
104 |
|
|
CHECK( 4 == q++ );
|
105 |
|
|
s0.wait();
|
106 |
|
|
s0.wait();
|
107 |
|
|
CYG_TEST_PASS_FINISH("Thread 2 OK");
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
// ------------------------------------------------------------------------
|
111 |
|
|
|
112 |
|
|
static void entry1( CYG_ADDRWORD data )
|
113 |
|
|
{
|
114 |
|
|
CHECK( 1 == q++ );
|
115 |
|
|
s1.wait();
|
116 |
|
|
CHECK( 5 == q++ );
|
117 |
|
|
thread0->set_priority(9);
|
118 |
|
|
s0.post();
|
119 |
|
|
CHECK( 6 == q++ );
|
120 |
|
|
thread2->set_priority(3);
|
121 |
|
|
CHECK( 8 == q++ );
|
122 |
|
|
s2.post();
|
123 |
|
|
CHECK( 12 == q++ );
|
124 |
|
|
CHECK( 9 == thread0->get_priority() );
|
125 |
|
|
CHECK( 6 == thread1->get_priority() );
|
126 |
|
|
CHECK( 7 == thread2->get_priority() );
|
127 |
|
|
q = 100;
|
128 |
|
|
#if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \
|
129 |
|
|
&& defined(CYGSEM_KERNEL_SCHED_TIMESLICE)
|
130 |
|
|
thread2->set_priority(6);
|
131 |
|
|
CHECK( 6 == thread1->get_priority() );
|
132 |
|
|
CHECK( 6 == thread2->get_priority() );
|
133 |
|
|
|
134 |
|
|
while ( 100 == q )
|
135 |
|
|
;
|
136 |
|
|
CHECK( 101 == q++ );
|
137 |
|
|
s1.wait();
|
138 |
|
|
CHECK( 103 == q++ );
|
139 |
|
|
#endif
|
140 |
|
|
s0.post();
|
141 |
|
|
s1.wait();
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
// ------------------------------------------------------------------------
|
145 |
|
|
|
146 |
|
|
static void entry2( CYG_ADDRWORD data )
|
147 |
|
|
{
|
148 |
|
|
CHECK( 2 == q++ );
|
149 |
|
|
s0.post();
|
150 |
|
|
CHECK( 7 == q++ );
|
151 |
|
|
s2.wait();
|
152 |
|
|
CHECK( 9 == q++ );
|
153 |
|
|
thread1->set_priority(6);
|
154 |
|
|
CHECK( 10 == q++ );
|
155 |
|
|
thread2->set_priority(2);
|
156 |
|
|
CHECK( 11 == q++ );
|
157 |
|
|
thread2->set_priority(7);
|
158 |
|
|
|
159 |
|
|
#if !(CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES) \
|
160 |
|
|
&& defined(CYGSEM_KERNEL_SCHED_TIMESLICE)
|
161 |
|
|
CHECK( 6 == thread1->get_priority() );
|
162 |
|
|
CHECK( 6 == thread2->get_priority() );
|
163 |
|
|
|
164 |
|
|
CHECK( 100 == q++ );
|
165 |
|
|
while ( 101 == q )
|
166 |
|
|
;
|
167 |
|
|
CHECK( 102 == q++ );
|
168 |
|
|
s1.post();
|
169 |
|
|
#endif
|
170 |
|
|
s0.post();
|
171 |
|
|
s2.wait();
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
// ------------------------------------------------------------------------
|
176 |
|
|
|
177 |
|
|
void thread2_main( void )
|
178 |
|
|
{
|
179 |
|
|
CYG_TEST_INIT();
|
180 |
|
|
|
181 |
|
|
thread0 = new_thread( entry0, 0 );
|
182 |
|
|
thread1 = new_thread( entry1, 1 );
|
183 |
|
|
thread2 = new_thread( entry2, 2 );
|
184 |
|
|
|
185 |
|
|
thread0->resume();
|
186 |
|
|
thread1->resume();
|
187 |
|
|
thread2->resume();
|
188 |
|
|
|
189 |
|
|
thread0->set_priority(5);
|
190 |
|
|
thread1->set_priority(6);
|
191 |
|
|
thread2->set_priority(7);
|
192 |
|
|
|
193 |
|
|
if( 9 >= CYG_THREAD_MIN_PRIORITY )
|
194 |
|
|
CYG_TEST_FAIL_FINISH("Test requires priorities up to 9");
|
195 |
|
|
|
196 |
|
|
if( 2 <= CYG_THREAD_MAX_PRIORITY )
|
197 |
|
|
CYG_TEST_FAIL_FINISH("Test requires priorities as low as 2");
|
198 |
|
|
|
199 |
|
|
Cyg_Scheduler::start();
|
200 |
|
|
|
201 |
|
|
CYG_TEST_FAIL_FINISH("Unresolved");
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
// ------------------------------------------------------------------------
|
205 |
|
|
|
206 |
|
|
externC void
|
207 |
|
|
cyg_start( void )
|
208 |
|
|
{
|
209 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
210 |
|
|
cyg_hal_invoke_constructors();
|
211 |
|
|
#endif
|
212 |
|
|
thread2_main();
|
213 |
|
|
}
|
214 |
|
|
// ------------------------------------------------------------------------
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
#else // CYGPKG_KERNEL_SMP_SUPPORT etc
|
218 |
|
|
|
219 |
|
|
// ------------------------------------------------------------------------
|
220 |
|
|
|
221 |
|
|
externC void
|
222 |
|
|
cyg_start( void )
|
223 |
|
|
{
|
224 |
|
|
CYG_TEST_INIT();
|
225 |
|
|
CYG_TEST_PASS_FINISH("Thread2 test requires:\n"
|
226 |
|
|
"defined(CYGIMP_THREAD_PRIORITY) &&\n"
|
227 |
|
|
"!defined(CYGPKG_KERNEL_SMP_SUPPORT)\n");
|
228 |
|
|
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
// ------------------------------------------------------------------------
|
232 |
|
|
|
233 |
|
|
#endif // CYGPKG_KERNEL_SMP_SUPPORT etc
|
234 |
|
|
|
235 |
|
|
// ------------------------------------------------------------------------
|
236 |
|
|
// EOF thread2.cxx
|