Revision c87b95b0 src/sim/cscheduler.cc

View differences:

src/sim/cscheduler.cc
151 151
        throw cRuntimeError("EEFScheduler is not supported in sequential mode. Activate Threadpool or use cSequentialScheduler.");
152 152
    }
153 153

  
154
    updateIES();
155
    return getFirstEvent();
156
}
154 157

  
158
void cEEFScheduler::updateIES() {
155 159
    cMessage *msg = NULL;
156 160
    cSimpleModule* mod = NULL;
157 161
    cAsyncModule* aMod = NULL;
158

  
159 162
#ifdef NOBARRIER
160 163

  
161 164
    while (!(sim->msgQueue.empty()))
......
202 205
    }
203 206

  
204 207
    if (msg) sim->msgQueue.insert(msg);
205

  
206
    if(independentEventsHeap.empty()) {
207
        if (!sim->msgQueue.empty()) {
208
            // Do we have to wait for a barrier?
209
            if (sim->threadPool) sim->threadPool->waitAtBarrier(&(sim->msgQueue));
210
            return sim->msgQueue.removeFirst();
211
        }
212
    } else {
213
        return independentEventsHeap.getFirst();
214
    }
215
    // At this point, both IES and FES are empty
216
    //
217
    // if there is no event left and we don't use the threadpool, end the sim
218
    //
219
    if (!sim->threadPool)
220
    throw cTerminationException(eENDEDOK);
221

  
222
    //
223
    // If we did not get a valid msg from the queue, but there are still
224
    // barrier messages left, we wait:
225
    //
226
    while (sim->msgQueue.empty() && !sim->threadPool->barrierEmpty())
227
    {
228
        __asm__ ("pause");
229
    }
230
    msg = sim->msgQueue.removeFirst();
231

  
232
    if (msg) return msg;
233

  
234
    //
235
    // If there is still no message in the queue, there are
236
    // also no barriers left (else we would have waited), and we quit:
237
    //
238

  
239
    else
240
    throw cTerminationException(eENDEDOK);
241

  
242 208
#else
243 209
    cBarrierMessage* barrier = NULL;
244 210
    /*
......
251 217
        if (barrier != NULL)
252 218
        {
253 219
            /*
254
             * If the barrier has already been signaled, we can just delete it, as we would not have to wait here
220
             * If the barrier has already been signaled, we can just delete it,
221
             * as we would not have to wait here
255 222
            */
256 223
            if(!barrier->isValid()) {
257 224
                delete barrier;
......
270 237
            else
271 238
            {
272 239
                sim->msgQueue.insert(msg);
273
                return independentEventsHeap.getFirst();
240
                return;
274 241
            }
275 242
        }
276 243

  
......
283 250

  
284 251
            if (!aMod->mayParallelize(msg, duration))
285 252
            {
286
                if (independentEventsHeap.empty())
287
                {
288
                    return msg;
289
                }
290
                else
291
                {
292
                    sim->msgQueue.insert(msg);
293
                    return independentEventsHeap.getFirst();
294
                }
253
                sim->msgQueue.insert(msg);
254
                return;
295 255
            }
296 256
            // create a new barrier and schedule it
297 257
            cBarrierMessage* barrier = new cBarrierMessage();
......
315 275
        }
316 276
        else //Not a AsyncModule
317 277
        {
318
            if (independentEventsHeap.empty())
319
            {
320
                return msg;
321
            }
322
            else
323
            {
324
                sim->msgQueue.insert(msg);
325
                return independentEventsHeap.getFirst();
326
            }
278
            sim->msgQueue.insert(msg);
279
            return;
327 280
        }
328 281

  
329 282
    } // while (!(sim->msgQueue.empty()))
330
/*
331
 * the FES is empty
332
 * check if the independent event set is also empty
333
 */
334
if (independentEventsHeap.empty())
335
{
336
    throw cTerminationException(eENDEDOK);
337
}
338
return independentEventsHeap.getFirst();
339 283
#endif
340 284
}
341 285

  
286
cMessage* cEEFScheduler::getFirstEvent() {
287
#ifdef NOBARRIER
288
    cMessage *msg = NULL;
289
    if(independentEventsHeap.empty()) {
290
            if (!sim->msgQueue.empty()) {
291
                // Do we have to wait for a barrier?
292
                if (sim->threadPool) sim->threadPool->waitAtBarrier(&(sim->msgQueue));
293
                return sim->msgQueue.removeFirst();
294
            }
295
        } else {
296
            return independentEventsHeap.getFirst();
297
        }
298
        // At this point, both IES and FES are empty
299
        //
300
        // if there is no event left and we don't use the threadpool, end the sim
301
        //
302
        if (!sim->threadPool)
303
        throw cTerminationException(eENDEDOK);
304

  
305
        //
306
        // If we did not get a valid msg from the queue, but there are still
307
        // barrier messages left, we wait:
308
        //
309
        while (sim->msgQueue.empty() && !sim->threadPool->barrierEmpty())
310
        {
311
            __asm__ ("pause");
312
        }
313
        msg = sim->msgQueue.removeFirst();
342 314

  
315
        if (msg) return msg;
343 316

  
317
        //
318
        // If there is still no message in the queue, there are
319
        // also no barriers left (else we would have waited), and we quit:
320
        //
321

  
322
        else
323
        throw cTerminationException(eENDEDOK);
324
#else
325
        if (independentEventsHeap.empty())
326
        {
327
            if (sim->msgQueue.empty()) {
328
                /*
329
                 * Both Queues are empty, we are done
330
                 */
331
                throw cTerminationException(eENDEDOK);
332
            } else {
333
                /*
334
                 * In this case, we have sequential execution
335
                 */
336
                return sim->msgQueue.removeFirst();
337
            }
338
        }
339
        return independentEventsHeap.getFirst();
340
#endif
341
}
344 342

  
345 343
//-----
346 344
Register_Class(cRealTimeScheduler);

Also available in: Unified diff