-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCMachineFCFSPP.cpp
191 lines (149 loc) · 6.1 KB
/
SCMachineFCFSPP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*-----------------------------------------------------------------------------+
| |
| SCL - Simulation Class Library |
| |
| (c) 1994-98 Marc Diefenbruch, Wolfgang Textor |
| University of Essen, Germany |
| |
+---------------+-------------------+---------------+-------------------+------+
| Module | File | Created | Project | |
+---------------+-------------------+---------------+-------------------+------+
|SCMachineFCFSPP|SCMachineFCFSPP.cpp| 13. Jul 1994 | SCL | |
+---------------+-------------------+---------------+-------------------+------+
| |
| Change Log |
| |
| Nr. Date Description |
| ----- -------- ------------------------------------------------------ |
| 001 |
| 000 11.07.94 Neu angelegt |
| |
+-----------------------------------------------------------------------------*/
/* Lineal
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
*/
/* Maschine mit Strategie "First-Come First-Serve" mit Prioritaeten und Preemptying
*
* Die Requests werden nach ihrer Prioritaet sortiert in eine Warteschlange einge-
* reiht. Wenn ein Bediener frei ist, wird das erste Element der Warteschlange
* bearbeitet. Wenn ein Request mit hoeherer oder gleicher Prioritaet ankommt, wird
* der Prozess mit der niedrigsten Prioritaet unterbrochen und als erster seiner
* Prioritaet in die Warteschlange eingereiht. Wenn mehrere Requests unterbrochen
* werden koennen, wird der aelteste Request unterbrochen.
*/
#include <string.h>
#include <float.h>
#include "SCStream.h"
#include "SCMachineFCFSPP.h"
#include "SCAutomaton.h"
#include "SCScheduler.h"
#include "SCRequest.h"
#include "SCRequestType.h"
#include "SCTraceControl.h"
#include "SCDebug.h"
#if _SC_DMALLOC
#include <dmalloc.h>
#endif
SCMachineFCFSPP::SCMachineFCFSPP (SCRunnableID pMachineID,
SCNatural pServers,
SCNatural pServices,
const SCDuration *const pSpeeds,
const char *pName,
SCObject *father) :
SCMachineLtd (pMachineID, scDiscFCFSPP, pServers, pServices,
pSpeeds, pName,
father)
{
if (IsVerbose())
SCScheduler::outputStream << "Creating " << *this << std::endl;
#if _SC_DEBUGOUTPUT
scDebugLog << SCScheduler::GetCurrentTime() << ": " << *this;
scDebugLog << " created" << std::endl;
#endif
}
SCMachineFCFSPP::~SCMachineFCFSPP (void)
{
if (IsVerbose())
SCScheduler::outputStream << "Deleting " << *this << std::endl;
}
void SCMachineFCFSPP::EnqueueRequest (SCRequest *request)
{
SCRequestIter iter (*GetWaitingQueue());
SCRequest * curRequest;
#if _SC_DEBUGOUTPUT
scDebugLog << SCScheduler::GetCurrentTime() << ": " << *this;
scDebugLog << " is queueing ";
scDebugLog << *request << std::endl;
#endif
for (curRequest = iter++;
curRequest;
curRequest = iter++)
{
if (curRequest->GetPriority() < request->GetPriority())
break;
}
if (curRequest) // found request with lower priority ?
GetWaitingQueue()->InsertBefore (request, curRequest->GetContainer());
else // new request has lowest priority !
GetWaitingQueue()->InsertAfter (request); // special case for append to queue
request->SetWaitStartTime(SCScheduler::GetCurrentTime());
}
void SCMachineFCFSPP::NewRequest (SCAutomaton *caller,
const SCRequestType *serviceType,
SCDuration serviceAmount,
SCNatural priority)
{
SCRequest * request;
request = new SCRequest (serviceType,
serviceAmount,
priority,
caller,
serviceAmount / Speed (serviceType));
assert (request);
#if _SC_VALIDATION_OPTIMIZE
SetModified();
#endif
/* Enter the new request into the waiting room of the machine */
EnqueueRequest (request);
if (IsTraceOn())
SCTraceControl::LogEvent (scTraceServiceRequest, this, request);
/* Enter the new request into the machine */
if (NumOfFreeServers() > 0 || // service room not full?
InterruptRequest (request, false)) // or request with lower prio?
{
/* Update all currently running requests before inserting the new one */
UpdateWork();
/* Remove finished requests */
FinishRequests();
/* Enter the new request into the service room of the machine */
StartRequest();
/* Determine next regular wakeup time */
Reschedule();
}
}
/* Validation stack and display functions */
void SCMachineFCFSPP::Size(SCSize *curSize) const
{
SCMachineLtd::Size(curSize);
}
SCBoolean SCMachineFCFSPP::Save (SCMem& saveArea) const
{
SCMachineLtd::Save (saveArea);
return true;
}
SCBoolean SCMachineFCFSPP::Restore (SCMem &saveArea)
{
SCMachineLtd::Restore (saveArea);
return true;
}
SCStream& operator<< (SCStream& pStream,
const SCMachineFCFSPP& pData)
{
return pData.Display(pStream); // virtuelle Funktion aufrufen
}
SCStream& SCMachineFCFSPP::Display (SCStream& pStream) const
{
pStream << "fcfspp ";
return SCMachineLtd::Display(pStream);
}