OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [kill.cxx] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        kill.cxx
4
//
5
//        Thread kill test
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):     nickg
44
// Contributors:  nickg
45
// Date:          1998-04-24
46
// Description:   Tests the functionality of thread kill() and
47
//                reinitalize().
48
//####DESCRIPTIONEND####
49
 
50
#include <pkgconf/kernel.h>
51
 
52
#include <cyg/kernel/thread.hxx>
53
#include <cyg/kernel/thread.inl>
54
#include <cyg/kernel/sched.hxx>
55
#include <cyg/kernel/mutex.hxx>
56
#include <cyg/kernel/sema.hxx>
57
 
58
#include <cyg/infra/testcase.h>
59
 
60
#ifdef CYGFUN_KERNEL_THREADS_TIMER
61
 
62
#include <cyg/kernel/sched.inl>
63
 
64
#define NTHREADS 3
65
 
66
#include "testaux.hxx"
67
 
68
// In general, this delay has to be long enough to account for slow targets
69
// and potential problems on e.g. the linux synthetic target to avoid
70
// potential problems due to timing inaccuracy and scheduling of Linux
71
// tasks. It is decreased further below for simulators.
72
int delay_ticks = 5;
73
 
74
 
75
static Cyg_Binary_Semaphore s0, s1;
76
 
77
volatile cyg_atomic thread0_state;
78
volatile cyg_atomic thread1_state;
79
volatile cyg_atomic thread2_state;
80
 
81
static void entry0( CYG_ADDRWORD data )
82
{
83
    Cyg_Thread *self = Cyg_Thread::self();
84
 
85
    thread0_state = 1;
86
 
87
    s0.wait();
88
 
89
    thread0_state = 2;
90
 
91
    CYG_TEST_FAIL_FINISH("Thread not killed");
92
 
93
    self->exit();
94
}
95
 
96
 
97
static void entry1( CYG_ADDRWORD data )
98
{
99
    Cyg_Thread *self = Cyg_Thread::self();
100
 
101
    thread1_state = 1;
102
 
103
    self->delay(delay_ticks);
104
 
105
    if( thread2_state != 1 )
106
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
107
 
108
    thread1_state = 2;
109
 
110
    thread[0]->kill();
111
 
112
    thread1_state = 3;
113
 
114
    thread[2]->kill();
115
 
116
    thread1_state = 4;
117
 
118
    self->delay(delay_ticks);
119
 
120
    thread1_state = 5;
121
    thread2_state = 0;
122
 
123
    thread[2]->reinitialize();
124
    thread[2]->resume();
125
 
126
    self->delay(delay_ticks);
127
 
128
    if( thread2_state != 1 )
129
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
130
 
131
    thread1_state = 6;
132
 
133
    self->delay(delay_ticks);
134
 
135
    if( thread2_state != 2 )
136
        CYG_TEST_FAIL_FINISH("Thread2 in wrong state");
137
 
138
    thread[2]->kill();
139
 
140
    thread1_state = 7;
141
 
142
    CYG_TEST_PASS_FINISH("Kill OK");
143
 
144
    Cyg_Thread::self()->exit();
145
}
146
 
147
static void entry2( CYG_ADDRWORD data )
148
{
149
    thread2_state = 1;
150
 
151
    while( thread1_state != 6 ) continue;
152
 
153
    thread2_state = 2;
154
 
155
    for(;;) continue;
156
 
157
}
158
 
159
void release_main(void)
160
{
161
    CYG_TEST_INIT();
162
 
163
    if (cyg_test_is_simulator)
164
        delay_ticks = 2;
165
 
166
    new_thread( entry0, 0);
167
    new_thread( entry1, 1);
168
    new_thread( entry2, 2);
169
 
170
    thread[0]->set_priority(5);
171
    thread[1]->set_priority(6);
172
    thread[2]->set_priority(7);
173
 
174
    Cyg_Scheduler::start();
175
 
176
    CYG_TEST_FAIL_FINISH("Not reached");
177
}
178
 
179
externC void
180
cyg_start( void )
181
{
182
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
183
    cyg_hal_invoke_constructors();
184
#endif
185
    release_main();
186
}
187
 
188
#else // ifdef CYGFUN_KERNEL_THREADS_TIMER
189
 
190
externC void
191
cyg_start( void )
192
{
193
    CYG_TEST_INIT();
194
    CYG_TEST_NA("Kernel threads timer disabled");
195
}
196
 
197
#endif // ifdef CYGFUN_KERNEL_THREADS_TIMER
198
 
199
// EOF kill.cxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.