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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [include/] [flag.hxx] - Blame information for rev 621

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

Line No. Rev Author Line
1 27 unneback
#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 Red Hat, 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 version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License along
26
// with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28
//
29
// As a special exception, if other files instantiate templates or use macros
30
// or inline functions from this file, or you compile this file and link it
31
// with other works to produce a work based on this file, this file does not
32
// by itself cause the resulting work to be covered by the GNU General Public
33
// License. However the source code for this file must still be made available
34
// in accordance with section (3) of the GNU General Public License.
35
//
36
// This exception does not invalidate any other reasons why a work based on
37
// this file might be covered by the GNU General Public License.
38
//
39
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40
// at http://sources.redhat.com/ecos/ecos-license/
41
// -------------------------------------------
42
//####ECOSGPLCOPYRIGHTEND####
43
//==========================================================================
44
//#####DESCRIPTIONBEGIN####
45
//
46
// Author(s):   hmt
47
// Contributors:        hmt
48
// Date:        1998-02-10
49
// Purpose:     Define Flag class interfaces
50
// Description: The classes defined here provide the APIs for flags.
51
// Usage:       #include 
52
//
53
//
54
//####DESCRIPTIONEND####
55
//
56
//==========================================================================
57
 
58
#include 
59
#include                      // assertion macros
60
#include                    // Cyg_Thread
61
 
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.