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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_LOTTERY_HXX
2
#define CYGONCE_KERNEL_LOTTERY_HXX
3
 
4
//==========================================================================
5
//
6
//      lottery.hxx
7
//
8
//      Lottery scheduler 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):   nickg
46
// Contributors:        nickg
47
// Date:        1997-09-10
48
// Purpose:     Define lottery scheduler implementation
49
// Description: The classes defined here are used as base classes
50
//              by the common classes that define schedulers and thread
51
//              things. A lottery scheduler provides each thread with a
52
//              share of the processor based on the number of tickets that
53
//              it owns.
54
// Usage:       Included according to configuration by
55
//              
56
//
57
//####DESCRIPTIONEND####
58
//
59
//==========================================================================
60
 
61
#include 
62
 
63
// -------------------------------------------------------------------------
64
// Customize the scheduler
65
 
66
#define CYGIMP_THREAD_PRIORITY  1       // Threads have changable priorities
67
 
68
#define CYG_THREAD_MIN_PRIORITY 1
69
#define CYG_THREAD_MAX_PRIORITY 0x7FFFFFFF
70
 
71
// set default scheduling info value for thread constructors.
72
#define CYG_SCHED_DEFAULT_INFO  CYG_THREAD_MAX_PRIORITY
73
 
74
#error Lottery Scheduler not yet complete, do not use!!!
75
 
76
// -------------------------------------------------------------------------
77
// Thread queue implementation.
78
// This class provides the (scheduler specific) implementation of the
79
// thread queue class.
80
 
81
class Cyg_ThreadQueue_Implementation
82
{
83
    friend class Cyg_Scheduler_Implementation;
84
    friend class Cyg_SchedThread_Implementation;
85
 
86
    Cyg_Thread *queue;
87
 
88
protected:
89
 
90
    // API used by Cyg_ThreadQueue
91
 
92
                                        // Add thread to queue
93
    void                enqueue(Cyg_Thread *thread);
94
 
95
                                        // return first thread on queue
96
    Cyg_Thread          *highpri();
97
 
98
                                        // remove first thread on queue
99
    Cyg_Thread          *dequeue();
100
 
101
                                        // remove specified thread from queue
102
    void                remove(Cyg_Thread *thread);
103
 
104
                                        // test if queue is empty
105
    cyg_bool            empty();
106
 
107
    void                rotate();       // Rotate the queue
108
};
109
 
110
inline cyg_bool Cyg_ThreadQueue_Implementation::empty()
111
{
112
    return queue == NULL;
113
}
114
 
115
// -------------------------------------------------------------------------
116
// This class contains the implementation details of the scheduler, and
117
// provides a standard API for accessing it.
118
 
119
class Cyg_Scheduler_Implementation
120
    : public Cyg_Scheduler_Base
121
{
122
    friend class Cyg_ThreadQueue_Implementation;
123
    friend class Cyg_SchedThread_Implementation;
124
 
125
    // All runnable threads are kept on a single run queue
126
    // in MRU order.
127
    Cyg_ThreadQueue_Implementation     run_queue;
128
 
129
    cyg_uint32  rand_seed;
130
 
131
    cyg_int32   total_tickets;
132
 
133
protected:
134
 
135
    Cyg_Scheduler_Implementation();     // Constructor
136
 
137
    // The following functions provide the scheduler implementation
138
    // interface to the Cyg_Scheduler class. These are protected
139
    // so that only the scheduler can call them.
140
 
141
    // choose a new thread
142
    Cyg_Thread  *schedule();
143
 
144
    // make thread schedulable
145
    void        add_thread(Cyg_Thread *thread);
146
 
147
    // make thread un-schedulable
148
    void        rem_thread(Cyg_Thread *thread);
149
 
150
    // register thread with scheduler
151
    void        register_thread(Cyg_Thread *thread);
152
 
153
    // deregister thread
154
    void        deregister_thread(Cyg_Thread *thread);
155
 
156
    // Test the given priority for uniqueness
157
    cyg_bool    unique( cyg_priority priority);
158
 
159
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
160
 
161
    // If timeslicing is enbled, define a scheduler
162
    // entry point to do timeslicing. This will be
163
    // called from the RTC DSR.
164
 
165
protected:
166
 
167
    static cyg_count32         timeslice_count;
168
 
169
public:
170
    void timeslice();
171
 
172
    static void reset_timeslice_count();
173
 
174
#endif
175
 
176
 
177
};
178
 
179
// -------------------------------------------------------------------------
180
// Cyg_Scheduler_Implementation inlines
181
 
182
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
183
 
184
inline void Cyg_Scheduler_Implementation::reset_timeslice_count()
185
{
186
    timeslice_count = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS;
187
}
188
 
189
#endif
190
 
191
// -------------------------------------------------------------------------
192
// Scheduler thread implementation.
193
// This class provides the implementation of the scheduler specific parts
194
// of each thread.
195
 
196
class Cyg_SchedThread_Implementation
197
{
198
    friend class Cyg_Scheduler_Implementation;
199
    friend class Cyg_ThreadQueue_Implementation;
200
 
201
    Cyg_Thread *next;                   // next thread in queue
202
    Cyg_Thread *prev;                   // previous thread in queue
203
 
204
    void insert( Cyg_Thread *thread );  // Insert thread in front of this
205
 
206
    void remove();                      // remove this from queue
207
 
208
protected:
209
 
210
    cyg_priority        priority;       // current thread priority == tickets held
211
 
212
    cyg_priority        compensation_tickets;   // sleep compensation
213
 
214
    Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info);
215
 
216
    void yield();                       // Yield CPU to next thread
217
 
218
};
219
 
220
// -------------------------------------------------------------------------
221
#endif // ifndef CYGONCE_KERNEL_LOTTERY_HXX
222
// EOF lottery.hxx

powered by: WebSVN 2.1.0

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