1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// bin_sem1.cxx
|
4 |
|
|
//
|
5 |
|
|
// Binary semaphore 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 binary semaphore functionality.
|
47 |
|
|
//####DESCRIPTIONEND####
|
48 |
|
|
|
49 |
|
|
#include <pkgconf/kernel.h>
|
50 |
|
|
|
51 |
|
|
#include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start()
|
52 |
|
|
#include <cyg/kernel/thread.hxx> // Cyg_Thread
|
53 |
|
|
#include <cyg/kernel/thread.inl>
|
54 |
|
|
|
55 |
|
|
#include <cyg/kernel/sema.hxx>
|
56 |
|
|
|
57 |
|
|
#include <cyg/infra/testcase.h>
|
58 |
|
|
|
59 |
|
|
#include <cyg/kernel/sched.inl>
|
60 |
|
|
|
61 |
|
|
#define NTHREADS 2
|
62 |
|
|
|
63 |
|
|
#include "testaux.hxx"
|
64 |
|
|
|
65 |
|
|
static Cyg_Binary_Semaphore s0(true), s1(false), s2;
|
66 |
|
|
|
67 |
|
|
static volatile cyg_ucount8 q = 0;
|
68 |
|
|
|
69 |
|
|
static void entry0( CYG_ADDRWORD data )
|
70 |
|
|
{
|
71 |
|
|
s0.wait();
|
72 |
|
|
CHECK( 0 == q++ );
|
73 |
|
|
s1.post();
|
74 |
|
|
s0.wait();
|
75 |
|
|
CHECK( 2 == q++ );
|
76 |
|
|
CHECK( ! s0.posted() );
|
77 |
|
|
CHECK( ! s0.trywait() );
|
78 |
|
|
s0.post();
|
79 |
|
|
CHECK( 3 == q++ );
|
80 |
|
|
CHECK( s0.posted() );
|
81 |
|
|
s1.post();
|
82 |
|
|
CHECK( ! s2.posted() );
|
83 |
|
|
s2.wait();
|
84 |
|
|
CHECK( 5 == q++ );
|
85 |
|
|
CYG_TEST_PASS_FINISH("Binary Semaphore 1 OK");
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
static void entry1( CYG_ADDRWORD data )
|
89 |
|
|
{
|
90 |
|
|
CHECK( s1.posted() );
|
91 |
|
|
s1.wait();
|
92 |
|
|
CHECK( 1 == q++ );
|
93 |
|
|
CHECK( ! s0.posted() );
|
94 |
|
|
s0.post();
|
95 |
|
|
s1.wait();
|
96 |
|
|
CHECK( 4 == q++ );
|
97 |
|
|
CHECK( s0.posted() );
|
98 |
|
|
CHECK( s0.trywait() );
|
99 |
|
|
CHECK( ! s0.posted() );
|
100 |
|
|
s2.post();
|
101 |
|
|
s0.wait();
|
102 |
|
|
CYG_TEST_FAIL_FINISH("Not reached");
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
void bin_sem1_main( void )
|
106 |
|
|
{
|
107 |
|
|
CYG_TEST_INIT();
|
108 |
|
|
|
109 |
|
|
new_thread( entry0, 0);
|
110 |
|
|
new_thread( entry1, 1);
|
111 |
|
|
|
112 |
|
|
#ifdef CYGIMP_THREAD_PRIORITY
|
113 |
|
|
thread[0]->set_priority( 4 );
|
114 |
|
|
thread[1]->set_priority( 5 ); // make sure the threads execute as intended
|
115 |
|
|
#endif
|
116 |
|
|
|
117 |
|
|
Cyg_Scheduler::start();
|
118 |
|
|
|
119 |
|
|
CYG_TEST_FAIL_FINISH("Not reached");
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
externC void
|
123 |
|
|
cyg_start( void )
|
124 |
|
|
{
|
125 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
126 |
|
|
cyg_hal_invoke_constructors();
|
127 |
|
|
#endif
|
128 |
|
|
bin_sem1_main();
|
129 |
|
|
}
|
130 |
|
|
// EOF bin_sem1.cxx
|