Project

General

Profile

Revision a3be1d55

IDa3be1d55d349d5c722e7358b42efe4eb720c04fa

Added by Simon Tenbusch about 9 years ago

[eefscheduler] moved barrierwaiting to scheduler
- now the scheduler always returns a non barrier event

View differences:

src/sim/cscheduler.cc
86 86
    // If there is still no message in the queue, there are
87 87
    // also no barriers left (else we would have waited), and we quit:
88 88
    //
89

  
89 90
    else
90
        throw cTerminationException(eENDEDOK);
91
    throw cTerminationException(eENDEDOK);
91 92

  
92 93
#else
94
    cMessage *msg = NULL;
95
    cBarrierMessage* barrier = NULL;
93 96

  
94
    cMessage *msg = sim->msgQueue.removeFirst();
95
    if (!msg)
96
        throw cTerminationException(eENDEDOK);
97
    while (msg == NULL)
98
    {
99
        msg = sim->msgQueue.removeFirst();
100
        if (!msg)
101
            throw cTerminationException(eENDEDOK);
102
        /*
103
         * If we have a Barriermsg, we wait
104
         */
105
        barrier = dynamic_cast<cBarrierMessage*> (msg);
106
        if (barrier != NULL)
107
        {
108
            // wait for the task to complete
109
            barrier->wait();
110
            delete barrier;
111
            msg = NULL;
112
        }
113
    }
97 114

  
98
    cBarrierMessage* barrier = dynamic_cast<cBarrierMessage*> (msg);
99
            if (barrier != NULL)
100
            {
101
                return msg;
102
            }
103 115
    cSimpleModule* mod = (cSimpleModule*) sim->getModule(msg->getArrivalModuleId());
104
    cAsyncModule* aMod = NULL;
105 116
    if (mod->isAsyncModule())
106 117
    {
107
        aMod = (cAsyncModule*) mod;
108
        simtime_t now = cThreadPool::getSimTime();
118
        cAsyncModule* aMod = (cAsyncModule*) mod;
119
        simtime_t now = msg->getArrivalTime();
109 120
        simtime_t duration = aMod->getProcessingDelay(msg);
110
        if(aMod->mayParallelize(msg,duration)) {
121

  
122
        if (aMod->mayParallelize(msg, duration))
123
        {
111 124
            msg->setEventDuration(duration);
112 125
            // create a new barrier and schedule it
113 126
            cBarrierMessage* barrier = new cBarrierMessage();
......
117 130
            sim->msgQueue.insert(barrier);
118 131
        }
119 132
    }
120

  
121 133
    return msg;
122 134
#endif
123 135
}
......
175 187
    throw cTerminationException(eENDEDOK);
176 188

  
177 189
#else
190

  
191
    //TODO: Optimize to save state when the IES has to be emptied
192

  
178 193
    cMessage *msg;
179 194
    cBarrierMessage* barrier;
195
    cSimpleModule* mod;
196
    cAsyncModule* aMod;
180 197
    /*
181 198
     * Fill up independent event heap
182 199
     */
......
188 205
        {
189 206
            /*
190 207
             * if we hit a barrier, we are done and return the first independent msg
191
             * or the barrier if no such event exists
208
             * or we have wait at the barrier if no independent event exists
192 209
             */
193
            if (independentEventsHeap.empty()) {
194
                return msg;
195
            } else {
210
            if (independentEventsHeap.empty())
211
            {
212
                barrier->wait();
213
                delete barrier;
214
                continue;
215
            }
216
            else
217
            {
196 218
                sim->msgQueue.insert(msg);
197 219
                return independentEventsHeap.getFirst();
198 220
            }
199

  
200 221
        }
201
        cSimpleModule* mod = (cSimpleModule*) sim->getModule(msg->getArrivalModuleId());
202
        cAsyncModule* aMod = NULL;
222

  
223
        mod = (cSimpleModule*) sim->getModule(msg->getArrivalModuleId());
224
        aMod = NULL;
203 225
        if (mod->isAsyncModule())
204 226
        {
205 227
            aMod = (cAsyncModule*) mod;
206
        }
207
        if (aMod == NULL)
208
        {
209
            if (independentEventsHeap.empty()) {
210
                return msg;
211
            } else {
212
                sim->msgQueue.insert(msg);
213
                return independentEventsHeap.getFirst();
214
            }
215
        }
216
        else
217
        {
218
            simtime_t now = cThreadPool::getSimTime();
228
            simtime_t now = msg->getArrivalTime();
219 229
            simtime_t duration = aMod->getProcessingDelay(msg);
220 230
            msg->setEventDuration(duration);
221 231

  
222
            if(!aMod->mayParallelize(msg,duration)) {
223
                if (independentEventsHeap.empty()) {
232
            if (!aMod->mayParallelize(msg, duration))
233
            {
234
                if (independentEventsHeap.empty())
235
                {
224 236
                    return msg;
225
                } else {
237
                }
238
                else
239
                {
226 240
                    sim->msgQueue.insert(msg);
227 241
                    return independentEventsHeap.getFirst();
228 242
                }
229 243
            }
230

  
231

  
232 244
            // create a new barrier and schedule it
233 245
            cBarrierMessage* barrier = new cBarrierMessage();
234 246
            barrier->setArrival(aMod, -1, now + duration);
235 247
            msg->setBarrier(barrier);
236 248
            // insert user supplied message in task queue.
237 249
            sim->msgQueue.insert(barrier);
238
            printf("adding to IEH: %s, tend= %f, now First in IEH: ",((cSimpleModule*)sim->getModule(msg->getArrivalModuleId()))->getName(),SIMTIME_DBL(msg->getTend()));
250

  
251
            printf(
252
                    "adding to IEH: %s, tend= %f, now First in IEH: ",
253
                    ((cSimpleModule*) sim->getModule(msg->getArrivalModuleId()))->getName(),
254
                    SIMTIME_DBL(msg->getTend()));
255

  
239 256
            independentEventsHeap.insert(msg);
240
            printf("%s, length=%i\n", ((cSimpleModule*)sim->getModule(independentEventsHeap.peekFirst()->getArrivalModuleId()))->getName(), independentEventsHeap.length());
241 257

  
242
        }
258
            printf(
259
                    "%s, length=%i\n",
260
                    ((cSimpleModule*) sim->getModule(
261
                            independentEventsHeap.peekFirst()->getArrivalModuleId()))->getName(),
262
                    independentEventsHeap.length());
243 263

  
244
    }
264
        }
265
        else //Not a AsyncModule
266
        {
267
            if (independentEventsHeap.empty())
268
            {
269
                return msg;
270
            }
271
            else
272
            {
273
                sim->msgQueue.insert(msg);
274
                return independentEventsHeap.getFirst();
275
            }
276
        }
245 277

  
246
    /*
247
     * the big queue is empty
248
     * check if the independent event set is also empty
249
     */
250
    if (independentEventsHeap.empty()) {
251
        throw cTerminationException(eENDEDOK);
252
    }
253
    return independentEventsHeap.getFirst();
278
    } // while (!(sim->msgQueue.empty()))
279
/*
280
 * the FES is empty
281
 * check if the independent event set is also empty
282
 */
283
if (independentEventsHeap.empty())
284
{
285
    throw cTerminationException(eENDEDOK);
286
}
287
return independentEventsHeap.getFirst();
254 288
#endif
255 289
}
256 290

  

Also available in: Unified diff