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/] [mutex1.cxx] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//        mutex1.cxx
4
//
5
//        Mutex test 1
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-24
46
// Description:   Tests basic mutex functionality.
47
// Omissions:     Timed wait.
48
//####DESCRIPTIONEND####
49
 
50
#include <pkgconf/kernel.h>
51
 
52
#include <cyg/kernel/sched.hxx>        // Cyg_Scheduler::start()
53
#include <cyg/kernel/thread.hxx>       // Cyg_Thread
54
 
55
#include <cyg/kernel/mutex.hxx>
56
 
57
#include <cyg/infra/testcase.h>
58
 
59
#include <cyg/kernel/sched.inl>
60
#include <cyg/kernel/thread.inl>
61
 
62
 
63
#define NTHREADS 3
64
#include "testaux.hxx"
65
 
66
static Cyg_Mutex m0, m1;
67
static Cyg_Condition_Variable cvar0( m0 ), cvar1( m0 ), cvar2( m1 );
68
 
69
static cyg_ucount8 m0d=0, m1d=0;
70
 
71
static void finish( cyg_ucount8 t )
72
{
73
    m1.lock(); {
74
        m1d |= 1<<t;
75
        if( 0x7 == m1d )
76
            CYG_TEST_PASS_FINISH("Mutex 1 OK");
77
        cvar2.wait();
78
    }
79
    CYG_TEST_FAIL_FINISH("Not reached");
80
}
81
 
82
static void entry0( CYG_ADDRWORD data )
83
{
84
    m0.lock(); {
85
        CHECK( ! m0.trylock() );
86
        m1.lock(); {
87
            CHECK( ! m0.trylock() );
88
        } m1.unlock();
89
    } m0.unlock();
90
 
91
    m0.lock(); {
92
        while ( 0 == m0d )
93
            cvar0.wait();
94
        CHECK( 1 == m0d++ );
95
        cvar0.signal();
96
        while ( 4 != m0d )
97
            cvar1.wait();
98
        CHECK( 4 == m0d );
99
    } m0.unlock();
100
 
101
    finish( data );
102
}
103
 
104
static void entry1( CYG_ADDRWORD data )
105
{
106
    m0.lock(); {
107
        CHECK( m1.trylock() ); {
108
        } m1.unlock();
109
    } m0.unlock();
110
 
111
    m0.lock(); {
112
        CHECK( 0 == m0d++ );
113
        cvar0.broadcast();
114
    } m0.unlock();
115
 
116
    m0.lock(); {
117
        while( 1 == m0d )
118
            cvar0.wait();
119
        CHECK( 2 == m0d++ );
120
        cvar0.signal();
121
        while (3 == m0d )
122
            cvar1.wait();
123
    } m0.unlock();
124
 
125
    finish( data );                 // At most 1 finish inside m0 lock
126
}
127
 
128
static void entry2( CYG_ADDRWORD data )
129
{
130
    m0.lock(); {
131
        while( 3 != m0d ) {
132
            cvar0.wait();
133
        }
134
        CHECK( 3 == m0d++ );
135
        cvar1.broadcast();
136
    } m0.unlock();
137
 
138
    finish( data );
139
}
140
 
141
void mutex1_main( void )
142
{
143
    CYG_TEST_INIT();
144
 
145
    new_thread(entry0, 0);
146
    new_thread(entry1, 1);
147
    new_thread(entry2, 2);
148
 
149
    Cyg_Scheduler::start();
150
 
151
    CYG_TEST_FAIL_FINISH("Not reached");
152
}
153
 
154
externC void
155
cyg_start( void )
156
{
157
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
158
    cyg_hal_invoke_constructors();
159
#endif
160
    mutex1_main();
161
}
162
// EOF mutex1.cxx

powered by: WebSVN 2.1.0

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