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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [flag.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_FLAG_HXX
2
#define CYGONCE_KERNEL_FLAG_HXX
3
 
4
//==========================================================================
5
//
6
//      flag.hxx
7
//
8
//      Flag object class declarations
9
//
10
//==========================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):   hmt
46
// Contributors:        hmt
47
// Date:        1998-02-10
48
// Purpose:     Define Flag class interfaces
49
// Description: The classes defined here provide the APIs for flags.
50
// Usage:       #include 
51
//
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include 
58
#include                      // assertion macros
59
#include                    // Cyg_Thread
60
 
61
#include                    // queue implementation
62
// -------------------------------------------------------------------------
63
 
64
// Flag object.  This class implements a queue of threads waiting for a
65
// boolean expression of the flag value (an integer) to become true; all
66
// relevant threads are awoken, not just the first.  A variant on this is
67
// the single-bit flag, which is implemented by means of default arguments.
68
 
69
#ifdef CYGIMP_FLAGS_16BIT
70
typedef cyg_uint16 Cyg_FlagValue;
71
#define CYG_FLAGS_SIZE 16
72
#endif
73
#ifdef CYGIMP_FLAGS_32BIT
74
typedef cyg_uint32 Cyg_FlagValue;
75
#define CYG_FLAGS_SIZE 32
76
#endif
77
#ifdef CYGIMP_FLAGS_64BIT
78
typedef cyg_uint64 Cyg_FlagValue;
79
#define CYG_FLAGS_SIZE 64
80
#endif
81
 
82
#ifndef CYG_FLAGS_SIZE
83
typedef cyg_uint32 Cyg_FlagValue;
84
#define CYG_FLAGS_SIZE 32
85
#endif
86
 
87
 
88
 
89
class Cyg_Flag
90
{
91
private:
92
    Cyg_FlagValue value;
93
 
94
    class FlagWaitInfo
95
    {
96
    public:
97
        Cyg_FlagValue   allmask;        // these are separate words to
98
        Cyg_FlagValue   anymask;        // save time in wakeup.
99
        Cyg_FlagValue   value_out;      // return the value that satisfied
100
        cyg_bool        do_clear;
101
 
102
        FlagWaitInfo() { value_out = 0; }
103
    };
104
 
105
    Cyg_ThreadQueue     queue;          // Queue of waiting threads
106
 
107
public:
108
 
109
    CYGDBG_DEFINE_CHECK_THIS
110
 
111
    Cyg_Flag( Cyg_FlagValue init = 0 ); // Constructor
112
    ~Cyg_Flag();                        // Destructor
113
 
114
    void
115
    setbits( Cyg_FlagValue arg = ~0 );  // -OR- the arg in
116
    // not inlined; this function awakens affected threads.
117
 
118
    void
119
    maskbits( Cyg_FlagValue arg = 0 );  // -AND- it in
120
    // this is not inlined because it needs to lock the scheduler;
121
    // it only really does value &= arg; nobody can be awoken in consequence.
122
 
123
    typedef cyg_uint8 WaitMode;
124
    // These values are chosen to map directly to uITRON for emulation
125
    // purposes:
126
    static const WaitMode AND = 0;      // all specified bits must be set
127
    static const WaitMode OR  = 2;      // any specified bit must be set
128
    static const WaitMode CLR = 1;      // clear value when satisfied
129
    static const WaitMode MASK= 3;      // might be useful
130
 
131
    // Wait for a match on our pattern, according to the flags given.
132
    // Return the matching value, or zero if interrupted.
133
    Cyg_FlagValue
134
    wait( Cyg_FlagValue pattern, WaitMode mode );
135
 
136
    // Wait for a match on our pattern, with an absolute timeout.
137
    // Return the matching value, or zero if timed out/interrupted.
138
    // (zero cannot match any pattern).
139
#ifdef CYGFUN_KERNEL_THREADS_TIMER
140
    Cyg_FlagValue
141
    wait( Cyg_FlagValue pattern, WaitMode mode,
142
          cyg_tick_count abs_timeout );
143
#endif
144
    // Test for a match on our pattern, according to the flags given.
145
    // Return the matching value if success, else zero.
146
    Cyg_FlagValue
147
    poll( Cyg_FlagValue pattern, WaitMode mode );
148
 
149
    inline Cyg_FlagValue
150
    peek()                              // Get current value
151
    {
152
        return value;                   // NOT atomic wrt threads
153
    }
154
 
155
    inline cyg_bool
156
    waiting()                           // Any threads waiting?
157
    {
158
        return !queue.empty();
159
    }
160
};
161
 
162
 
163
 
164
// -------------------------------------------------------------------------
165
#endif // ifndef CYGONCE_KERNEL_FLAG_HXX
166
// EOF flag.hxx

powered by: WebSVN 2.1.0

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