-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCMachineFCFSPNP.cpp
188 lines (145 loc) · 5.79 KB
/
SCMachineFCFSPNP.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
/*-----------------------------------------------------------------------------+
| |
| SCL - Simulation Class Library |
| |
| (c) 1994-98 Marc Diefenbruch, Wolfgang Textor |
| University of Essen, Germany |
| |
+-------------------+-------------------+---------------+------------------+---+
| Module | File | Created | Project | |
+-------------------+-------------------+---------------+------------------+---+
| SCMachineFCFSPNP |SCMachineFCFSPNP.cc| 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 ohne Preempting
*
* Die Requests werden nach ihrer Prioritaet sortiert in eine Warteschlange einge-
* reiht. Wenn ein Bediener frei ist, wird das erste Element der Warteschlange
* bearbeitet. Die Bearbeitung eines Request kann nicht durch einen anderen an-
* kommenden Request mit hoeherer Prioritaet unterbrochen werden.
*/
#include <string.h>
#include <float.h>
#include "SCStream.h"
#include "SCMachineFCFSPNP.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
SCMachineFCFSPNP::SCMachineFCFSPNP (SCRunnableID pMachineID,
SCNatural pServers,
SCNatural pServices,
const SCDuration *const pSpeeds,
const char *pName,
SCObject *father) :
SCMachineLtd (pMachineID, scDiscFCFSPNP, 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
}
SCMachineFCFSPNP::~SCMachineFCFSPNP (void)
{
if (IsVerbose())
SCScheduler::outputStream << "Deleting " << *this << std::endl;
}
void SCMachineFCFSPNP::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)
GetWaitingQueue()->InsertBefore (request, curRequest->GetContainer());
else
GetWaitingQueue()->InsertAfter (request); // special case for append to queue
request->SetWaitStartTime(SCScheduler::GetCurrentTime());
}
void SCMachineFCFSPNP::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); // request must wait!
if (IsTraceOn())
SCTraceControl::LogEvent (scTraceServiceRequest, this, request);
if (NumOfFreeServers() > 0) // free server available ?
{
/* Update all currently running requests before inserting the new one */
UpdateWork();
/* Remove finished requests */
FinishRequests();
/* Enter the new request into the machine */
StartRequest();
/* Determine next regular wakeup time */
Reschedule();
}
}
/* Validation stack and display functions */
void SCMachineFCFSPNP::Size(SCSize *curSize) const
{
SCMachineLtd::Size(curSize);
}
SCBoolean SCMachineFCFSPNP::Save (SCMem& saveArea) const
{
SCMachineLtd::Save (saveArea);
return true;
}
SCBoolean SCMachineFCFSPNP::Restore (SCMem &saveArea)
{
SCMachineLtd::Restore (saveArea);
return true;
}
SCStream& operator<< (SCStream& pStream,
const SCMachineFCFSPNP& pData)
{
return pData.Display(pStream); // virtuelle Funktion aufrufen
}
SCStream& SCMachineFCFSPNP::Display (SCStream& pStream) const
{
pStream << "fcfspnp ";
return SCMachineLtd::Display(pStream);
}